The CommonsBlog

PSA: Another (Small) AlarmManager Regression

This is not nearly as big of an issue as yesterday’s WebView regresssion or even the original Android 5.1 AlarmManager regression.

However, the filed issue for that earlier AlarmManager regression has turned up another regression: on Android 5.1+, you cannot set an alarm to occur less than 5 seconds in the future from now.

Honestly, I am surprised they allow them to be that low, as that means a setExact() “loop” can achieve every-five-second alarms. And, as a Googler points out, this would not be a good idea in the first place:

Note that if you are doing work every 5 seconds it’s quite possible your device is not managing to go to sleep at all, and the most likely behavior is that it will enter power collapse at ~ 3.5 seconds after your work is done, then wake up at the 5-second boundary again. This will probably burn more battery than simply holding a wakelock across the entire scanning period, because coming out of power collapse is very expensive compared to staying awake for a short time.

If you attempt to set an alarm to occur sooner than 5 seconds from now, your initial alarm time is moved to the 5-seconds mark, just as setting a repeat period of less than one minute silently extends that period to one minute.

Find out about new posts on the CommonsBlog via the Atom feed, or follow @CommonsWare on Twitter!