设备启动时的 BroadcastReceiver 和 AlarmManager

发布于 2024-12-22 19:38:25 字数 381 浏览 2 评论 0原文

我有一个活动,其中警报在用户可以选择的时间启动;时间存储在数据库中。 然后调用 BroadcastReceiver,在特定时间触发通知。 所以一切正常,但现在我想在设备重新启动时启动警报,但我不知道我到底该如何做到这一点。 根据此网站警报通知我应该实现另一个在设备启动时启动的BroadcastReceiver并像我在其他广播接收器中那样发出警报。 但在所有其他站点上,他们建议实现一个广播接收器,该接收器启动额外的服务并发出警报。 另外我想知道设备启动时启动的 BroadcastReceiver 是否可以访问我的数据库,其中存储了要触发的警报的日期和时间。 谢谢大家

i've got a Activity in which an alarm is started at a time which can be choosen by the user; the time is stored in a database.
Than a BroadcastReceiver is called which fires a notification at the specific time.
So everything is working, but now i want to start the alarms also when the device is rebooted and i don't know how exactly i can do this.
According to this site Alarm Notification i should implement an other BroadcastReceiver which starts when the device is booted and fires the alarms like i do in my other BroadCastReceiver.
But on all other sites, they advice to implement a BroadcastReceiver which starts an extra service and than fires the alarms.
Also i wonder if it's possible that the BroadcastReceiver which could be started when the device is booted does have access to my database in which the date and time of the alarms to be fired are stored.
Thanks everybody

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

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

发布评论

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

评论(1

月依秋水 2024-12-29 19:38:25

是的,因为它是同一应用程序的一部分,所以它可以访问数据库。因此,您可以收到设备启动的通知,然后使用数据库中的时间设置警报,或触发警报。或者两者兼而有之。

希望这有帮助。

Yes, as it's part of the same application it has access to the database. So you could receive notification of device boot then set your alarms up using the time in the database, or fire the alarms. Or both.

Hope this helps.

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