2

My app and activity is in my list of recent apps when I receive a notification. When I click on the notification, I want the intent of the notification to be honored. In my case I want to restart the activity (brute force) and pass in the new intent: so, finish then re-create. I am reading about such tags as FLAG_ACTIVITY_NEW_TASK and FLAG_ACTIVITY_SINGLE_TOP but I don't understand them enough to know how to force a "finish then re-create` of my activity. And, oh, the activity in question is MainActivity.

The snippet inside GcmListenerService uses

intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

for sending the notification intent

Alternatively

If I go with onNewIntent things get complicated because there maybe DialogFragments being displayed, etc. And I would have to clear everything. That is why finish then re-create seem like the simplest solution to me.

Katedral Pillon
  • 14,534
  • 25
  • 99
  • 199

1 Answers1

0

Intent flag FLAG_ACTIVITY_CLEAR_TOP should produce the desired behavior. The documentation for Tasks and Back Stack says this in the section for Using Intent Flags:

If the launch mode of the designated activity is "standard", it too is removed from the stack and a new instance is launched in its place to handle the incoming intent. That's because a new instance is always created for a new intent when the launch mode is "standard".

The documentation for FLAG_ACTIVITY_CLEAR_TOP describes the same behavior in more detail.

Bob Snyder
  • 37,759
  • 6
  • 111
  • 158