1

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.

  • By the way this question has nothing to do with the Java Timer class (that should not be used in Android anyway) so it's not a duplicate of the mentioned question. – BladeCoder Aug 01 '15 at 19:22

1 Answers1

1

The most efficient way is to only schedule the next alarm of each group using AlarmManager.

Use setExact() in API 19+ and set() on older versions. It's required to use setExact() when targeting newer versions if you want the alarm to go off at the exact planned time.

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.

BladeCoder
  • 12,779
  • 3
  • 59
  • 51
  • never tried that and it's not documented in the official docs but you can also (as i heard) wake up a Service, not only BroadcastReceiver – pskink Jul 31 '15 at 21:13
  • When you use a BroadcastReceiver you have the advantage that the system will create an implicit wake lock while you are handling the Intent. If you want to perform long-running operations in response to an alarm, you should use a WakefulBroadcastReceiver which starts an IntentService. – BladeCoder Aug 01 '15 at 19:19