Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How inexact is setInexactRepeating() for AlarmManager?

Tags:

android

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?

like image 660
b_yng Avatar asked Aug 20 '11 02:08

b_yng


People also ask

Is AlarmManager deprecated?

IntentService + WakefulBroadcastReceiver + AlarmManager are deprecated with API 26 (Android 8.0 Oreo).

What is setInexactRepeating?

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.

How does alarm Manager work?

AlarmManager is a bridge between application and Android system alarm service. It can send a broadcast to your app (which can be completely terminated by user) at a scheduled time and your app can then perform any task accordingly.


1 Answers

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.

like image 72
rmmh Avatar answered Oct 31 '22 01:10

rmmh