I currently have a Tab screen in my application. I use a notification to notify the user of a state change in my application and in normal circumstances when the user clicks on the notification it will return to this tab screen.
Here is the code I use for this:
String ns = Context.NOTIFICATION_SERVICE;
mNotificationManager = (NotificationManager) context.getSystemService(ns);
Intent notificationIntentRegState = new Intent();
ComponentName cn = new ComponentName(context, TabScreenActivity.class);
notificationIntentRegState.setComponent(cn);
contentIntentRegState = PendingIntent.getActivity(context, 0, notificationIntentRegState, 0);
notificationRegStateText = context.getString(R.string.app_name);
notificationRegState = new Notification(icon, notificationRegStateText, 0);
notificationRegState.setLatestEventInfo(context, notificationRegStateText, context.getString(R.string.notification_text, contentIntentRegState);
mNotificationManager.notify(3, notificationRegState);
However in my application the user can start another activity from the TabScreen and when this activity is “active” I want the notification to bring the user to the new activity and not the tabscreen activity. But when the notification is clicked it always goes to the Tab screen.
Is it possible to make sure the notification always directs the user to the most recent activity?
You could recreate the last activity that has been created by user, in response to notification beeing clicked.
in your pending activity, you could add an extra data to remmeber which activity to show :
where getCurrrentActivityID() returnin a constant that you use to identify the last activity launched.
And, in the onCreateMethod of your tabScreen, you could check the intent that you received and the extra param to launch that activity again in response to a click on notification
With, of course, you tabScreen filtering the intent name “showTabScreen” in your manifest.xml file.
Regards,
Stéphane