views:

191

answers:

2

Hello,

1/I don't want to notify user if this one is already running my app in foreground,
is it possible before create nofification to check if my app is not in front ?

2/if app is in background, is it possible to bring last state in front ?
I know that Os can destroy some Activity, but is it possible to restore last state, don't start a new Intent?
because if i start a new Intent and i push back, old Intent appear it's not very beautiful to have 2 identical intent launch.

Thanks

NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);
Intent notificationIntent = new Intent(this, z_finish.class);

PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
Notification notification = new Notification(icon, tickerText, when);
notification.flags |= Notification.FLAG_AUTO_CANCEL;

notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
final int HELLO_ID = 1;
mNotificationManager.notify(HELLO_ID, notification); 
A: 

is it possible before create nofification to check if my app is not in front ?

Your activities will have to tell the service when they are being paused and resumed; the service can then decide whether to display the Notification or not.

if app is in background, is it possible to bring last state in front ?

I am not quite certain what "last state" is. Try FLAG_ACTIVITY_CLEAR_TOP in your Intent.

CommonsWare
NSchubhan
I also tried this... make a fake Activity that just calls "finish", sending the user back to the last Activity. Problem is, if they press "back" until they're out of the app, they can't get back into it by using the notification (it just closes itself back to their home screen.) http://stackoverflow.com/questions/3568250/use-a-persistent-notification-to-allow-the-user-to-return-to-running-android-app
Slobaum
A: 

if your app is in singletask mode then the last state will be saved even if you relaunch it

Siddhartho