13

I need to set a repeating alarm every X hours that would even fire in doze mode. However, the only Apis available in AlarmManager for Android 23 are setExactAndAllowWhileIdle and setAndAllowWhileIdle which are not for repeating alarms.

I am wondering if I should reschedule the alarm every time it fires? or is there any better solution?

lyc001
  • 777
  • 1
  • 10
  • 25
  • Can this still be done in Oreo and above.`setExactAndAllowWhileIdle` and set a repeating alarm every X interval that would even fire in doze mode. Does anyone has a sample how can I do that. – Valentin Gjorgoski Aug 28 '19 at 12:18

1 Answers1

14

I am wondering if I should reschedule the alarm every time it fires?

That is exactly what you should do.

The idea behind doze is to attempt to prevent draining the battery. Repeated alarms drain battery, so the builtin way to repeat alarms by passing an extra parameter was removed in android 6. It can still be done, but as you were wondering, that requires you to manually reschedule the alarm.

Be sure to reschedule the alarm immediately when it fires, before doing anything else that could go wrong and prevent the alarm from being rescheduled.

Tim
  • 41,901
  • 18
  • 127
  • 145