Android:如果显示应用程序,则不显示通知
1/如果该应用程序已在前台运行我的应用程序,我不想通知用户,
在创建通知之前是否可以检查我的应用程序是否不在前面?
2/如果应用程序在后台,是否可以将最后的状态放在前面?
我知道Os可以破坏一些Activity,但是是否可以恢复最后的状态,而不启动一个新的Intent?
因为如果我启动一个新的意图并推迟,旧的意图就会出现,启动两个相同的意图并不是很漂亮。
谢谢
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);
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);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在创建通知之前是否可以检查我的应用程序是否不在前面?
您的活动必须在暂停和恢复时告知服务;然后,服务可以决定是否显示
通知
。我不太确定“最后状态”是什么。尝试在您的
FLAG_ACTIVITY_CLEAR_TOP
代码>意图。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.I am not quite certain what "last state" is. Try
FLAG_ACTIVITY_CLEAR_TOP
in yourIntent
.如果您的应用程序处于单任务模式,那么即使您重新启动它,也会保存最后的状态
if your app is in singletask mode then the last state will be saved even if you relaunch it