开发者

How inexact is setInexactRepeating() for AlarmManager?

开发者 https://www.devze.com 2023-03-29 04:42 出处:网络
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 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 inte开发者_如何转开发rval?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号