Android 在所需的 Activity 中阻止通知
可能的重复:
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
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.