Skip to content Skip to sidebar Skip to footer

Alarmmanager Isn't Working

I know there are a lot of questions like this, but none of the solutions helped me. I try to schedule a BroadcastReciever using the AlarmManager. For now, all it should do is make

Solution 1:

Can you please try this one ?

int trigger_time= System.currentTimeMillis() + 30 * 1000;   

if(Build.VERSION.SDK_INT >= 19) {
     alarmManager.setExact(AlarmManager.RTC_WAKEUP, trigger_time, pendingIntent);
 } else {
     alarmManager.set(AlarmManager.RTC_WAKEUP, trigger_time, pendingIntent);
 }

Edit:

Difference between setRepeating and setInexactRepeating:

Decide how precise your alarm needs to be

Choosing the alarm type is often the first step in creating an alarm. A further distinction is how precise you need your alarm to be.

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.

For the rare app that has rigid time requirements as example, the alarm needs to fire precisely at 12:00 p.m. everyday then use setRepeating().

Hope this will help you.

Solution 2:

From the Docs : Note: Beginning in API 19, the trigger time passed to this method is treated as inexact: the alarm will not be delivered before this time, but may be deferred and delivered some time later. The OS will use this policy in order to "batch" alarms together across the entire system, minimizing the number of times the device needs to "wake up" and minimizing battery use. In general, alarms scheduled in the near future will not be deferred as long as alarms scheduled far in the future.

Applications whose targetSdkVersion is before API 19 will continue to get the previous alarm behavior: all of their scheduled alarms will be treated as exact.

So what Hiren Patel has stated in his answer, will work for you.

Please tell us more about your test environment.

Post a Comment for "Alarmmanager Isn't Working"