(Skip down for a short summary)I am having trouble with the sequence of Activities in my application. The application has 3 Activity which flow from A to B to C (or C to B to A if back is pressed consecutively). In normal operation the app works fine, the problem I'm having is when a C2DM notification is received.
On receipt of a notification I would like the PendingIntent to be sent to the currently active activity or in the case of the app not running start the app.
In the notification receiver a PendingIntent is created with whatever the current activity is (which is held in the Application class), this too works fine.
However problems arise when the activity has changed from the one the PendingIntent was created with.
ie Notification is received in Activity C and the PendingIntent is created with an Intent pointing toward Activity C. The user navigates back to Activity A and clicks the notification which fires the intent off to and starts Activity C and I want it sent to A.
What I would like is to send the intent to whatever the current activity is. I have tried creating an Activity X which is the target of the PendingIntent and then when Activity X is created check which Activity is currently active which is stored in the Application class.
But I run into problems here too with Intent flags.I wanted to use the SINGLE_TOP flag for the intents I will use to ensure that onNewIntent is called for the current Activity so that I wont have problems with code in onCreate and onResume.
The problem I am encountering here is that Activity X is now at the top of the activity stack and single top doesn't because of that. I have tried using the NO_HISTORY and EXCLUDE_FROM_RECENTS flags for the pending intent so that Activity X isn't added to the stack and then use SINGLE_TOP for starting Activities A,B or C but its creating a new instance of them rather than using the one that exists.
In Summary:
4 activities: A,B,C,X and a receiver for notifications.
on receipt of a notification:
//not sure which is better to use or even if they're right for my purpose
start X with a PendingIntent with FLAG_ACTIVITY_NO_HISTORY or FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
Acivity X then gets the currently running activity from Application (A,B or C)
create an intent for the current activity (A,B or C) with FLAG_ACTIVITY_SINGLE_TOP
But onNewIntent is never called a new instance of A,B or C is created.
Is there a more sensible approach to this problem, are the flags I'm using wrong? Am I mis-understanding something fundamental about the way intent work, any help would be appreciated. And sorry for the long question. Also if code is required I can post it tomorrow as I'm away from my workstation.