Android - AlarmManager 恢复
感谢 TasKiller
,我有了可靠的方法来关闭从 AlarmManager
到我的 AppWidget
的更新!
现在,撇开讽刺不谈,我该如何从这样的事件中恢复过来呢?到目前为止,我只看到 Alerts
仅在重新启动手机后才会恢复。
我可以将恢复代码粘贴到几个地方,例如属于我的应用程序和小部件的各种Activity#onCreate
,但有更好的方法吗?
另外,如果警报正常怎么办 - 有没有办法检测到这一点而不运行 AlarmManager#setRepeating
?
或者多次运行有什么坏处吗?
Thanks to TasKiller
I have reliable way to shutdown updates coming to my AppWidget
from the AlarmManager
!
Now, sarcasm aside, how do I recover from such event? So far I only see that the Alerts
are resurrected only after rebooting the phone.
I can stick recovery code into few places such as various Activity#onCreate
that belong to my app and my widget but is there a better way?
Also what if the alerts are OK - is there a way to detect that and not run AlarmManager#setRepeating
?
Or is there a harm to run it multiple times?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我听说单一麦芽苏格兰威士忌有帮助。
仅当您挂钩
BOOT_COMPLETED
广播Intent
并重新建立警报时才会出现这种情况。任务杀手非常彻底,但它们无法阻止
BroadcastReceiver
接收系统广播,例如BOOT_COMPLETED
。欢迎您查找您想要接收的其他广播,以帮助重新获得控制并重新建立警报。您可以
cancel()
现有闹钟。因此,如果您担心可能出现重复,请cancel()
当前警报(如果警报不存在,希望会安静地失败),然后设置警报。I have heard that single-malt Scotch helps.
That is only if you are hooking the
BOOT_COMPLETED
broadcastIntent
and re-establishing the alarms.Task killers are remarkably thorough, but they cannot stop a
BroadcastReceiver
from receiving system broadcasts, likeBOOT_COMPLETED
. You are welcome to find some other broadcast that you would like to receive to help regain control and re-establish your alarms.You can
cancel()
an existing alarm. So, if you are concerned about possible duplicates,cancel()
the current alarm (which hopefully fails quietly if the alarm does not exist), then set the alarm.