16

So here's the deal... I've got to silence the user's phone when they have class. So I need an alarm to go off daily at a specific time, for each class.

So I'm thinking every class has their own alarm (interval set for a day). And the phone is silenced if class is in session the present day.

Here's my current code:

am.setInexactRepeating(AlarmManager.RTC_WAKEUP, startTime, 
                       DAY_IN_MILLISECONDS, start);

Will setInexactRepeating() be accurate enough to silence the phone within a few minutes over a day interval?

TheVillageIdiot
  • 40,053
  • 20
  • 133
  • 188
b_yng
  • 14,136
  • 6
  • 32
  • 35
  • note that the interval argument above needs to be one of the constants from `AlarmManager.INTERVAL_*`. – Jeffrey Blattman Apr 23 '12 at 14:59
  • @Jeffrey: Not entirely true. From the documentation "interval in milliseconds between subsequent repeats of the alarm. If this is one of INTERVAL_FIFTEEN_MINUTES, INTERVAL_HALF_HOUR, INTERVAL_HOUR, INTERVAL_HALF_DAY, or INTERVAL_DAY then the alarm will be phase-aligned with other alarms to reduce the number of wakeups. Otherwise, the alarm will be set as though the application had called setRepeating(int, long, long, PendingIntent)" – pmont Aug 20 '13 at 03:40
  • @pmont okay, but if you did that, your code probably isn't doing what you expect. – Jeffrey Blattman Aug 20 '13 at 17:19
  • I've added a more accurate answer for this here : http://stackoverflow.com/a/35305783/5550618 – Kas Hunt Feb 23 '16 at 21:18

1 Answers1

15

Probably not, especially if that's an interval of an entire day.

From the documentation:

Your alarm's first trigger will not be before the requested time, but it might not occur for almost a full interval after that time. In addition, while the overall period of the repeating alarm will be as requested, the time between any two successive firings of the alarm may vary. If your application demands very low jitter, use setRepeating(int, long, long, PendingIntent) instead.

rmmh
  • 6,997
  • 26
  • 37