通常のアプリケーションフローではない特別なアクティビティによって処理される通知を表示しようとしていて、バックスタックの処理が「正しい」ことを意味します:通知でスタックを元に戻す方法
- 通知アクティビティがアプリケーションの実行中に処理される場合、通知アクティビティは現在のスタックに表示されるはずです。通知から戻って、アプリケーションのどこにいても残してください。これは、アプリケーションが開かれている可能性があることに注意してください。
- アプリケーションが実行されていない間に通知が処理される場合、通知アクティビティはアプリケーションのメイン(初期)アクティビティに表示されます。
はこれまでのところ、私は通知を提示するために使用しているコードは次のとおりです。明確にするため
/**
* Show (or update) a notification for the current message set.
*
* @param showNotification true to use a high priority notification which will be immediately
* displayed (as opposed to just added to the status bar)
*/
private void createOrUpdateNotification(boolean showNotification) {
Message oldest = messages.get(0);
Message newest = messages.get(messages.size() - 1);
// Create the notification
NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
// Set notification data and appearance
.setContentTitle(title)
.setContentText(newest.message)
.setSmallIcon(smallIcon)
.setWhen(newest.when)
.setColor(ContextCompat.getColor(context, R.color.primary_color))
// Set notification options
.setAutoCancel(true)
.setCategory(NotificationCompat.CATEGORY_MESSAGE)
.setPriority(showNotification ? NotificationCompat.PRIORITY_HIGH : NotificationCompat.PRIORITY_LOW)
.setDefaults(NotificationCompat.DEFAULT_VIBRATE)
.setOnlyAlertOnce(!showNotification);
// Set up the action if the first (oldest) message has an intent builder
if(oldest.intent != null) {
TaskStackBuilder stackBuilder = TaskStackBuilder.create(context.getApplicationContext());
stackBuilder.addNextIntent(oldest.intent);
builder.setContentIntent(stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT));
}
NotificationManagerCompat.from(context).notify(notificationId, builder.build());
Log.i("notification created");
}
、Message.intent
は、通知処理アクティビティを開くように構成された単一の意図、です。
私の問題は、通知が開かれたときにアプリケーションが現在実行中で開いている場合、アプリケーションが閉じられ、空のスタックとアプリケーションのバックスタックに通知が表示されることです。
コンテンツのインテントが単一のインテントを含む保留中のインテントである場合は、ここでのケースであることが望ましいです。
私には何が欠けていますか?
私はあなたの質問を正しく理解しましたか?あなたは、通知を表示し、通知されている間に通知を出したスレッドを停止したいでしょうか?それはあなたが欲しいものですか? – Distjubo
いいえ通知はサービスによって生成されます。コンテンツアクションは、通常のアプリケーションフローから外れたアクティビティを開きます。そのアクティビティが終了すると、中断された所有アプリケーションアクティビティに戻りたいと思います。 –