Search code examples
androidalarmmanager

Inexact AlarmManager.setRepeating problems


I read in several articles that from API 19, all repeating alarms are inexact. Does this mean, that every device running Android 4.4 is unable to excecute exact repeatings? Or can I simply avoid this on such devices by using android:targetSdkVersion="18" in my project.

I think I do not need the features of API 19, but anyway, is it a better way to use setExact and update the time everytime the alarm is called? In my App the user should set a time at which he will be notified every day.


Solution

  • Does this mean, that every device running Android 4.4 is unable to excecute exact repeatings?

    It means that methods like set() and setRepeating() are now inexact by default if your android:targetSdkVersion is 19 or higher. There is a setExact() that you can use for exact alarms, and it would be up to you to implement the repeating part yourself, by calling setExact() again as part of processing the work triggered by a previous setExact() call.

    Or can I simply avoid this on such devices by using android:targetSdkVersion="18" in my project.

    Yes, you can avoid this. Eventually, though, something is going to force your hand to raise your android:targetSdkVersion to 19 or higher. That means that eventually, you will either need to adapt your app to inexact behavior or use setExact() as I describe above.

    is it a better way to use setExact and update the time everytime the alarm is called?

    Since setExact() does not exist prior to API Level 19, you can only use this on newer devices. Once you set your android:targetSdkVersion to 19 or higher, you will need to start using setExact() on those newer devices, while still using set() or setRepeating() on older devices. I am not aware of any benefits for using setExact() while still having an android:targetSdkVersion below 19.