Android - AlarmManager 恢复

发布于 2024-08-14 04:45:13 字数 367 浏览 10 评论 0原文

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

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

发布评论

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

评论(1

ゞ记忆︶ㄣ 2024-08-21 04:45:13

现在,撇开讽刺不谈,我该如何恢复
来自这样的事件?

我听说单一麦芽苏格兰威士忌有帮助。

到目前为止我只看到警报是
重启后才可以复活
电话。

仅当您挂钩 BOOT_COMPLETED 广播 Intent 并重新建立警报时才会出现这种情况。

任务杀手非常彻底,但它们无法阻止 BroadcastReceiver 接收系统广播,例如 BOOT_COMPLETED。欢迎您查找您想要接收的其他广播,以帮助重新获得控制并重新建立警报。

如果警报正常怎么办 - 是
有一种方法可以检测到并且不运行
AlarmManager#setRepeating?或者有没有
多次运行有什么坏处吗?

您可以cancel()现有闹钟。因此,如果您担心可能出现重复,请 cancel() 当前警报(如果警报不存在,希望会安静地失败),然后设置警报。

Now, sarcasm aside, how do I recover
from such event?

I have heard that single-malt Scotch helps.

So far I only see that the Alerts are
resurrected only after rebooting the
phone.

That is only if you are hooking the BOOT_COMPLETED broadcast Intent and re-establishing the alarms.

Task killers are remarkably thorough, but they cannot stop a BroadcastReceiver from receiving system broadcasts, like BOOT_COMPLETED. You are welcome to find some other broadcast that you would like to receive to help regain control and re-establish your alarms.

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?

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.

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