Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Just how inexact is setInexactRepeating() for AlarmManager?

I know this question has been asked before, here, but the answer given refers to documentation which is actually incredibly ambiguous. It says the inexact alarm might occur almost a "full interval" after the specified time. For alarms with an interval of a whole day, this would seem excessive.

The documentation does say here (under "RTC examples") that you can use inexact repeating for daily alarms, and gives an example of an inexact alarm being set for "approximately 2pm". Nobody in their right mind would think "approximately 2pm" might mean 1pm the next day, so it doesn't seem likely daily alarms at least can be "almost a full interval" after the specified time.

Is there any definite info out there about just how late an inexact alarm with a daily interval might be? Thanks.

(I know API 19 has "setWindow" but I'd like my app to work on older APIs too).

like image 325
joe_deniable Avatar asked Mar 10 '14 14:03

joe_deniable


People also ask

What is setInexactRepeating?

For most apps, setInexactRepeating() is the right choice. When you use this method, Android synchronizes multiple inexact repeating alarms and fires them at the same time. This reduces the drain on the battery.

In which API level did inexact timing become the default for AlarmManager?

The way that AlarmManager works was changed in API level 19 to help save battery life. It was so that events could be batched. What this means is that set() and setRepeating() will be inexact on API 19+. In API versions before 19, you can just use set, which will schedule an alarm for the exact time.

Is AlarmManager deprecated?

IntentService + WakefulBroadcastReceiver + AlarmManager are deprecated with API 26 (Android 8.0 Oreo).

How does an application get access to the AlarmManager?

How does an application get access to the AlarmManager? Use the AlarmManager() constructor to create an instance of the AlarmManager. Use the AlarmManager. newInstance() method to retrieve the singleton instance of the AlarmManager.


1 Answers

I've tested this with 5 consecutive alarms and the average delay, on my phone, was 11.8 minutes. This was with the interval between repeats set to INTERVAL_DAY.

like image 129
joe_deniable Avatar answered Sep 27 '22 17:09

joe_deniable