[英]Efficient way to program repeating alarms on Android, Java
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. 据我了解,有几种不同的方法可以在Java设备上实现我想实现的Android设备,这基本上是大多数智能手机的基本警报功能,但它们要大量使用。 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.
也就是说,除了在7:00、7:05、7:10、7:15和7:20发出警报外,您可以在7:00和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.
请注意,尽管我对Java有一定的经验,但对Android开发却不太了解。
The most efficient way is to only schedule the next alarm of each group using AlarmManager
. 最有效的方法是仅使用
AlarmManager
安排每个组的下一个警报。
Use setExact()
in API 19+ and set()
on older versions. 使用
setExact()
的API 19+和set()
旧版本。 It's required to use setExact()
when targeting newer versions if you want the alarm to go off at the exact planned time. 如果您希望警报在确切的计划时间响起,则在定位较新版本时需要使用
setExact()
。
When the alarm goes off it will wake up a registered BroadcastReceiver
, from which you can schedule the next alarm of the group, if any. 警报响起时,它将唤醒已注册的
BroadcastReceiver
,您可以从中安排该组的下一个警报(如果有)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.