Android Alarms: setRepeating vs set & reschedule
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?
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.
精彩评论