Android 在所需的 Activity 中阻止通知

发布于 2025-01-08 09:41:47 字数 540 浏览 3 评论 0原文

可能的重复:
Android:如何获取当前前台活动(来自服务)?
可选择启动 Activity 并使用来自 Android 服务的通知。仅在某个应用程序存在时启动或通知

如果我在 SyncService 中收到更新时生成通知,如果我已经在使用新信息的活动中,如何防止它出现?

这有点像当您使用 Gmail 应用程序时,当您在应用程序之外时会收到通知,但当您在应用程序中时却看不到它。

Possible Duplicate:
Android: How can I get the current foreground activity (from a service)?
Optionally starting activities and using notifications from services in Android. Only launch or notify if a certain app is present

If I produce a notification when I get an update in my SyncService, how do I prevent it from appearing if I am already in the activity that uses the new information?

It's kind of like when you use the gmail app, a notification will come when you are outside of the app, but you never see it when you are in it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

橘虞初梦 2025-01-15 09:41:47

CommonsWare 提供了一个解决方案作为

具体来说,他链接到这篇博文 ,它解释了有序广播的使用。

作为一个不太有效的想法,您可以在您的活动和服务中实现广播接收器,然后在发送通知之前,向您的活动发送广播意图并等待响应。如果您没有收到回复,请发出通知。

CommonsWare provides a solution to this as an answer to this question.

Specifically, he links to this blog post, which explains the use of ordered broadcasts.

As a not-so-efficient idea, you could implement a broadcast receiver in your activity and service, then before sending the notification, send a broadcast intent to your activity and wait for a response. If you don't get a response, raise the notification.

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