tl;dr: I want to keep the back stack to be able to navigate back, but when I don’t use the flags that clear the back stack, opening a notification that has a pending intent does nothing except opening the app, when the expected activity is in the back stack already and another activity is in foreground.
- I close my app.
- I send 3 fcm data messages to my app to create 3 notifications in
onMessageReceived()
:
- each one has a pending intent: n1 (notification 1) has main activity, n2 has activity X, and n3 also has main activity.
- I click on n1. as expected, main activity opens.
- I click on n2. as expected, activity X opens.
- I click on n3. nothing happens, besides the app opening. I still see activity 2 instead of main activity from the pending intent.
The behaviour explained above happens only when the app was closed before clicking on the first notification. It happens when I set the following combination of flags to the intent of the pending intents:
- none
FLAG_ACTIVITY_NEW_TASK
Once I set it to:
FLAG_ACTIVITY_NEW_TASK or FLAG_ACTIVITY_CLEAR_TASK
in step 5, main activity opens as expected. However, the back stack is gone. I still want to be able to go back to activity 2 and from there back to main activity.