ユーザーがアプリを一時停止したときに通知を送信しようとしています。簡単にするために、ユーザーは通知アクションを使用してアプリケーションにすばやく移動できます。これは私が使用しているコードです。Android 4より前のすべてのバージョンで機能しますが、どれが問題なのかわかりません
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("Titulo")
.setContentText("Titulo");
mBuilder.setOngoing(true);
// Creates an explicit intent for an Activity this
Intent resultIntent = new Intent(getApplicationContext(), MainActivity.class);
// put the flags
resultIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
// Adds the back stack for the Intent (but not the Intent itself)
stackBuilder.addParentStack(MainActivity.class);
// Adds the Intent that starts the Activity to the top of the stack
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent =
stackBuilder.getPendingIntent(
0,
PendingIntent.FLAG_UPDATE_CURRENT
);
mBuilder.setContentIntent(resultPendingIntent);
NotificationManager mNotificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
// mId allows you to update the notification later on.
mNotificationManager.notify(mId, mBuilder.build());
そのため、Android 4.0以降で通知を押すと、再開する代わりにアクティビティが再度作成されます。助けてください、私はそれを機能させることができません。
編集 (マニフェスト singletop を忘れる)
android:launchMode="singleTop"
同じ結果、動作しません...
アクティビティに地図が含まれています。私は新しいバージョンの Google マップを使用しています。v2.