Android - Repeating Alarms Allowed While Idle
Asked Answered
R

1

15

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?

Radiate answered 31/8, 2016 at 8:54 Comment(1)
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.Viccora
C
15

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.

Crespo answered 31/8, 2016 at 10:36 Comment(7)
Which method gets called to set this up? Are you supposed to call setAndAllowWhileIdle() or something else?Sherronsherry
Does this bypass Background Execution Limits in Oreo? I doubt it. I use this and still Android says Background start not allowed: serviceMerill
@Merill I don't see how that is related to scheduling alarmsCrespo
My bad. I was confusing this answer with scheduling alarms with service in PendingIntentMerill
How can i reschedule alarm in doze mode?Can I get reference linkProtomartyr
Thanks so much, I was searching something totally different and was just change this..Pasha
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.Viccora

© 2022 - 2024 — McMap. All rights reserved.