单击 Android Firebase 推送通知会重新启动应用程序

Sch*_*hm1 7 android firebase firebase-cloud-messaging firebase-notifications

当收到 Firebase 推送通知时,当应用处于后台时,Firebase 会自动显示通知。

此通知中包含的待处理 Intent 似乎始终包含该FLAG_ACTIVITY_NEW_TASK标志,这将导致在单击通知时重新启动应用程序,即使该应用程序已在后台处于活动状态。

有什么方法可以防止这种行为,而只是onNewIntent(intent)在主 Activity 上调用?

Sha*_*awn 5

launchMode活动的属性会影响活动的启动方式。

看:

https://developer.android.com/guide/topics/manifest/activity-element.html#lmode

singleTop, singleTask, 或singleInstance应该用于防止通知意图创建新的活动实例。

该标志FLAG_ACTIVITY_NEW_TASK不会影响正在创建的新活动,但会使启动的活动成为新任务的根。

看:

https://developer.android.com/reference/android/content/Intent.html#FLAG_ACTIVITY_NEW_TASK

和:

https://developer.android.com/guide/components/tasks-and-back-stack.html

希望这可以帮助。