I have an application that issues notifications that when selected start an activity. According to the Android docs I can use NavUtils.shouldUpRecreateTask to check whether the activity has been started directly (i.e. from the notification) or via a normal activity stack. However it gives the wrong answer. I’m testing this on JellyBean but using the support library.
Basically shouldUpRecreateTask always returns false, even when the activity has been started form the notification.
Any ideas on why shouldUpRecreateTask is failing to give the correct answer?
I still don’t know why shouldUpRecreateTask fails – looking at the source code for it doesn’t help much. But the solution is quite simple – I just add an extra flag value to the Intent that is attached to the notification, and check this in onCreate(). If it is set, then the Activity has been invoked from the notification, so the back stack has to be recreated.
The code looks like this: