Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - Repeating Alarms Allowed While Idle

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?

like image 499
lyc001 Avatar asked Aug 31 '16 08:08

lyc001


People also ask

How do I stop my Android phone from repeating an alarm?

Open your phone's Clock app . At the bottom, tap Alarm. On the alarm you want, tap the Down arrow . Cancel: To cancel an alarm scheduled to go off in the next 2 hours, tap Dismiss.

How do I set multiple alarms on Android?

If you want to set multiple alarms (repeating or single), then you just need to create their PendingIntent s with different requestCode . If requestCode is the same, then the new alarm will overwrite the old one.

How do I turn off alarm manager?

You can cancel the alarm like this: Intent intent = new Intent(this, Mote. class); PendingIntent pendingIntent = PendingIntent. getBroadcast(getApplicationContext(), 1253, intent, 0); AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE); alarmManager.


1 Answers

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.

like image 88
Tim Avatar answered Sep 30 '22 19:09

Tim