Say that the user has started my App and then switched off to use the Browser (so we have 2 sets of Tasks running). After a while, something happens to my app that requires the user's attention, so it posts a notification to notify the user. Is there a way to bring my App's task (and the Activity on top of the stack) out from the background when user clicks on my notification?
views:
31answers:
2
+1
A:
In your notification you call an intent to start your app, if you ensure it has the following flags then it will be brought to front rather than creating another instance:
Intent contentIntent = new Intent(this, ABC.class);
contentIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | INTENT.FLAG_ACTIVITY_SINGLE_TOP);
stealthcopter
2010-08-04 23:16:22
+1
A:
A notification usually comes with a PendingIntent (Notification.contentIntent
). Set this intent to your app to start an activity of your app.
There is only one Activity that is currently active - as soon as you switch to a different screen, the system will pause your activity (onPause, and very likely onDestroy), so you'll need to use an intent to bring resume your activity and bring it to the main screen.
EboMike
2010-08-04 23:17:14
When a PendingIntent starts ActivityA and an instance of ActivityA already resides somewhere in the background, does a new instance of ActivityA get created or does the existing instance get brought to focus?
zer0stimulus
2010-08-04 23:40:59
By default, the same instance will get focus. However, I'm not sure what you depend on (member variables? static variables?) The operating system may have killed off your activity as soon as it went to the background, so if there is any persistent data you want to stick around, you'll need to save it out first.
EboMike
2010-08-05 00:10:44