Android 闹钟:setRepeating 与 set &重新安排
我正在创建一个应用程序,每天都会提醒用户 X 次某事。我想知道是否最好创建:
- 多个
setRepeating
警报,间隔 24 小时 - 一个
setRepeating
警报,间隔 1 小时 [或半小时] 并决定是否提醒或只是返回 - 一个在运行时设置“下一个”警报的警报
- ,或者我没有想到的其他东西...
更具体地说,通过使用一种方法而不是其他?
I'm in the process of creating an app that will remind the user of something X times per day, every day. I'm wondering if it's better to create:
- Multiple
setRepeating
alarms with a 24-hour interval - One
setRepeating
alarm with a 1-hour interval [or half-hour] and decides whether to remind or just return - One
set
alarm that sets the "next" alarm when run - OR something else I haven't though of...
More specifically, what do I gain by using one method over the other?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的主要目标应该是调用尽可能少的闹钟,尤其是
_WAKEUP
闹钟,以节省电池寿命。因此,你的第二个项目并不是最好的解决方案。您的第二个目标应该是最大限度地减少维护这些警报所需的代码量,以简化您的生活。
通常,我认为“每天 X 次,每天”是“每 N 小时”之类的。在这种情况下,一次
setRepeating()
调用就足够了。如果“每天 X 次,每天”不太规律(例如,上午 8 点、中午和下午 4 点闹钟,但不是晚上 8 点、午夜或凌晨 4 点),那么您的第一个项目可能是最简单的。
如果“每天 X 次,每天”甚至不是那么规律,那么我会选择你的第三个子弹。
Your primary goal should be to invoke as few alarms as possible, particularly with
_WAKEUP
alarms, to save battery life. Hence, your second bullet is not the best solution.Your secondary goal should be to minimize the amount of code you need to maintain these alarms, just to simplify your life.
Usually, I think of "X times per day, every day" as being "every N hours" or something. In that case, a single
setRepeating()
call would suffice.If the "X times per day, every day" isn't quite that regular (e.g., alarms at 8am, noon, and 4pm, but not 8pm, midnight, or 4am), then your first bullet is probably the simplest.
If the "X times per day, every day" isn't even that regular, then I'd go with your third bullet.