1

This is strange, what is the reason method setInexactRepeating trigger approximately at given time rather then exact time.

I need to trigger alarm on every day basis at one particular time, i have said

Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
// Set the alarm's trigger time to 8:30 a.m.
calendar.set(Calendar.HOUR_OF_DAY, 8);
calendar.set(Calendar.MINUTE, 30);

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

I have set time 8:30 am in the calendar, when i shift device day to next day, alarm get trigger immediately even before i shift device time to 8:30am.

What is happening here, why i can't make exact trigger using this api, if any of you have experience this, could you share your experience. Thanks!

Akash Patel
  • 2,757
  • 1
  • 22
  • 30
chethan
  • 426
  • 5
  • 15
  • @Mike, it is "setInexactRepeating " – chethan Oct 07 '16 at 07:11
  • Yeah, sorry, I didn't consider the possible language barrier. "Inexact" means "not exact". If you want an exact, repeating alarm (since KitKat), you need to use a `setExact*()` method, and set the alarm again each time it fires. – Mike M. Oct 07 '16 at 07:14

1 Answers1

1

According to documentation (here) there is text:

As described above, 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—for example, the alarm needs to fire precisely at 8:30 a.m., and every hour on the hour thereafter—use setRepeating(). But you should avoid using exact alarms if possible.

With setInexactRepeating(), you can't specify a custom interval the way you can with setRepeating(). You have to use one of the interval constants, such as INTERVAL_FIFTEEN_MINUTES, INTERVAL_DAY, and so on.

I hope it could help You bit. There is also small example for it in previous link I gave You.

Community
  • 1
  • 1
deadfish
  • 11,996
  • 12
  • 87
  • 136