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);
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
.
if your app is in singletask mode then the last state will be saved even if you relaunch it
精彩评论