Ok, bear with me here
My App is composed of a splash screen activity (A) and the main activity (B). When the app starts, (A) is displayed for a bit and then it starts (B). Afterwards (A) is finished. This works fine under "normal" conditions. Here is the code to launch (B)
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
Intent mainIntent = new Intent(A.this, B.class);
startActivity(mainIntent);
finish();
}
}, SPLASH_DELAY);
When a notification arrives, and the user clicks on it. I'm starting (A) by means of a PendingIntent:
Intent mIntent = new Intent(this, A.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, mIntent, PendingIntent.FLAG_CANCEL_CURRENT);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this).setSmallIcon()... //build the whole notification
mBuilder.setContentIntent(contentIntent);
mNotificationManager.notify(0, mBuilder.build());
This starts (A) and then (B) and its all good.
However...
Once the app is showing on the screen and a second notification arrives (A) does not start again nor do I get any callback in (B)
Reading the documentation at http://developer.android.com/guide/components/tasks-and-back-stack.html#ActivityState I concluded that I should start (A) with the FLAG_ACTIVITY_NEW_TASK set (so that it starts a new task only if (A) isn't already running) and I should also start (B) with the flag FLAG_ACTIVITY_SINGLE_TOP (so I can get a callback to B.onNewIntent(), because B will be running). So I did
...
mainIntent.setFlags(FLAG_ACTIVITY_NEW_TASK);
....
mIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
....
but alas, no. The behaviour doesn't seem to change at all.
Am I missing something from the docs? It seems to me that FLAG_ACTIVITY_NEW_TASK should start (A) every time in my case, because by the time the second notification arrives. (A) has already finished but it just doesn't do anything.
Can you give me some lights on how to get any callback so I can display the correct info to the user?
Thanks