Nicolas Schubhan
Nicolas Schubhan

Reputation: 1756

Android : don't show Notification if app is shown

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); 

Upvotes: 4

Views: 6284

Answers (2)

Siddhartho
Siddhartho

Reputation: 39

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

Upvotes: 0

CommonsWare
CommonsWare

Reputation: 1007534

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.

Upvotes: 2

Related Questions