Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between setRepeating and setInexactRepeating of AlarmManager

What are the parameters of the following:

alarmMgr.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),                 AlarmManager.INTERVAL_FIFTEEN_MINUTES, alarmIntent); 

And of the following:

alarmMgr.setInexactRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),         AlarmManager.INTERVAL_DAY, alarmIntent); 

What is the difference and also how are the two different in terms of functionality?

like image 542
User3 Avatar asked Jan 20 '14 11:01

User3


1 Answers

Both examples schedule a repeating alarm that will send the given alarmIntent. On both cases, the first time it is sent will be immediate (calendar.getTimeInMillis() returns the current time). On both cases, the device will be woken up when the alarm needs to be sent (as evident by AlarmManager.RTC_WAKEUP).

There are two differences between these calls. The simpler one is that the intent will be sent every fifteen minutes on the first call, and every day on the second call (as you can see in the third parameter). The more complicated difference is the function call itself: setRepeating will schedule the first alarm for exactly every fifteen minutes; setInexactRepeating will schedule the second alarm for approximately every 24 hours, meaning it might deviate from that interval - with the advantage of consuming less power.

Do notice that this has changed in API 19, where these two calls are synonymous. See this guide, and this API documentation.

like image 191
PaF Avatar answered Sep 23 '22 06:09

PaF