Efficient way to program repeating alarms on Android, Java

时间:2015-07-31 20:55:14

标签: java android alarm

From what I was told, there are several different ways of implementing in Java for Android devices what I want to accomplish, which is basically to do what the basic alarm functionality in most smartphones does, but in bulk. That is to say that instead of having alarms for 7:00, 7:05, 7:10, 7:15, and 7:20, you can just put a group of alarms between 7:00 and 7:20. I want this to have three main repeating options: specified days of the week, specified days of the month, and one specified day with no repetition. I am trying to solve this on my own, though I would like to see how other programmers go about this problem. Note that while I am somewhat experienced in Java, I'm not too experienced with Android development.

1 个答案:

答案 0 :(得分:1)

最有效的方法是仅使用AlarmManager计划每个组的下一个警报。

在API 19+中使用setExact(),在旧版本上使用set()。如果您希望闹钟在确切的计划时间内关闭,则在定位较新版本时需要使用setExact()

当闹铃响起时,它会唤醒已注册的BroadcastReceiver,您可以从中安排该群组的下次闹铃(如果有)。