I've got a simple use case. I have activity open like below:
A > B > C
Now, I get a push notification.
I do the following in my GCMIntentService
class:
In onMessage
,
Intent notificationIntent = new Intent(context, A.class);
PendingIntent contentIntent =
PendingIntent.getActivity(context,0, notificationIntent,
PendingIntent.FLAG_CANCEL_CURRENT);
notification.setContentIntent(contentIntent);
notificationIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP );
My expectation is that activities B, C
should be removed from Activity stack
and you should be re-directed to activity A
.
What is happening is, however, A
gets opened; but when you hit back button I get C, B, A
again in that order!!
What is it that I'm doing wrong?
Here are the things I tried:
I've experimented with
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
,notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP, Intent.FLAG_ACTIVITY_SINGLE_TOP);
I've kept a static reference to the last foreground activity and passed that as
context
.
Nothing seems to work.