Android:如果显示应用程序,则不显示通知

发布于 2024-09-12 21:48:54 字数 768 浏览 3 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

赠我空喜 2024-09-19 21:48:55

在创建通知之前是否可以检查我的应用程序是否不在前面?

您的活动必须在暂停和恢复时告知服务;然后,服务可以决定是否显示通知

如果应用程序在后台,是吗?
可以将最后一个状态放在前面

我不太确定“最后状态”是什么。尝试在您的 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.

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.

软的没边 2024-09-19 21:48:55

如果您的应用程序处于单任务模式,那么即使您重新启动它,也会保存最后的状态

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文