When receiving a Firebase push notification, while the App is backgrounded, Firebase automatically displays a notification.
The pending Intent included in this notification seems to always include the FLAG_ACTIVITY_NEW_TASK
flag, which will cause the App to be restarted when the notification is clicked, even if the App is already alive in the background.
Is there any way to prevent this behaviour and simply have onNewIntent(intent)
on the main Activity invoked instead?
The launchMode
attribute of the activity affects how the activity is launched.
see:
https://developer.android.com/guide/topics/manifest/activity-element.html#lmode
singleTop
, singleTask
, or singleInstance
should be used to prevent the notification intent from creating a new activity instance.
The flag FLAG_ACTIVITY_NEW_TASK
doesn't influence a new activity being created, but makes the launched activity the root of a new task.
see:
https://developer.android.com/reference/android/content/Intent.html#FLAG_ACTIVITY_NEW_TASK
and:
https://developer.android.com/guide/components/tasks-and-back-stack.html
Hope this helps.
in AndroidManifest.xml
set your Activity launchMode
to singleTask
should fix this:
<activity
......
android:launchMode="singleTask"
>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With