我需要我的坚持标识的通知 [英] Do I need to persist my Notification IDs

查看:113
本文介绍了我需要我的坚持标识的通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个报警的应用程序,用户可以设置多个闹钟。当警报响起的应用程序只显示其中点击将推出的主要活动画面和移除通知。当通知

每个报警都有自己的通知这是我的问题来的;如果有多个Noitifications显示,当用户点击一个我想清楚我所有的应用程序的通知。要做到这一点,我需要跟踪的通知当前显示的ID。什么是这样做的推荐的方法?

我想这将需要持续的一个通知已经创建并显示我的应用程序的过程可以尽快杀死。我的想法是否正确?


解决方案

  

要做到这一点我需要跟踪的通知当前显示的ID。


或者就叫 cancelAll() NotificationManager ,取消所有未完成的通知。


  

什么是这样做的推荐的方法?


为了安全起见,你应该使用一些持久性数据存储(例如,文件),为你的进程可能会去的的报警器之间。


  

我想这将需要持续的一个通知已经创建并显示我的应用程序的过程可以尽快杀死。我的想法是否正确?


它当然可以下一个报警之前被杀死,因为在最近的其他问题。

I have an alarm application where users can set multiple alarms. When an alarm goes off the app simply displays a Notification which when clicked will launch the main activity screen and remove the Notification.

Each alarm gets its own Notification which is where my question comes in; if there are multiple Noitifications showing, when the user clicks one I would like to clear all of my app's Notifications. To do this I need to track the IDs of the Notifications currently showing. What is the recommended way of doing this?

I suppose these will need to be persisted as my app's process could be killed as soon as a Notification has been created and displayed. Is my thinking correct?

解决方案

To do this I need to track the IDs of the Notifications currently showing.

Or just call cancelAll() on NotificationManager, to cancel all your outstanding notifications.

What is the recommended way of doing this?

To be safe, you should use some persistent data store (e.g., file), as your process might go poof between alarms.

I suppose these will need to be persisted as my app's process could be killed as soon as a Notification has been created and displayed. Is my thinking correct?

It could certainly be killed before the next alarm, as discussed in your other recent question.

这篇关于我需要我的坚持标识的通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆