Search code examples
androidalarmmanagerandroid-alarmsrepeatingalarm

Alarm Manager not getting called with Google Nexus 4


I have developed one Android app. I need to set Alarms for certain operations.

The problem is that the Alarm receiver works fine with all other devices but with Google Nexus 4 it sometimes getting called sometime not! :-(

When I set alarm it prints the log as below which is 5 minutes later than current time.

Alarm set for : Fri Jun 20 06:07:00 GMT+00:00 2014

But when the time arrives it sometimes get called sometime not! :-(

I have put log inside the receiver, it prints it sometime.

Please help! Thanks!


Solution

  • Since API19, alarm manager is bit random:

    Note: Beginning with API 19 (KITKAT) alarm delivery is inexact: the OS will shift alarms in order to minimize wakeups and battery use. There are new APIs to support applications which need strict delivery guarantees; see setWindow(int, long, long, PendingIntent) and setExact(int, long, PendingIntent). Applications whose targetSdkVersion is earlier than API 19 will continue to see the previous behavior in which all alarms are delivered exactly when requested.

    http://developer.android.com/reference/android/app/AlarmManager.html