Alarmmanager Alarm Delay response

Source: Internet
Author: User


The project makes an alarm clock that requires the alarm to respond on time and in a timely manner. When the alarm clock set up a small number of times, is relatively reliable, basic can respond on time. But if the app sets up too many alarms, there are some bugs that have a delayed response to the alarm, sometimes a few seconds later, sometimes a few minutes later.


To view the Alarmmanager API documentation, find the following:


Note: Beginning in API, the trigger time Passed to this (Set) methodis treated as inexact : The alarm is not being delivered before this time, butMay be deferred and delivered some time later. The OS would use this policy on order to "batch" alarms together across the entire system, minimizing the number of times T He device needs to ' wake up ' and minimizing battery use. In general, alarms scheduled in the near future is not being deferred as long as alarms scheduled far on the future. With the new batching policy, delivery ordering guarantees is not as strong as they were previously. If the application sets multiple alarms, it is possible this these alarms ' actual delivery ordering may not match the Orde R of their requested delivery times. If Your application has strong ordering requirements There is other APIs so can use To get the necessary behavior; See SetWindow (int, long, long, pendingintent) and setexact (int, long, pendingintent).Applications whose targetsdkversion is before API would continue to get the previous alarm behavior:all of their schedu LED alarms would be treated as exact.
This means that, starting with Api19, the alarm set by the set method may occur deferred (latency) because the OS is not recommended to set too many alarms due to minimizing device wake-up and battery loss considerations. If you really need an alarm to respond on time, you can use the Setexact method.


modified to resolve as follows:

int APILevel = Build.VERSION.SDK_INT;

Pendingintent pendingintent = setpendingintent (mcontext, note);

Long Triggeratmillis = gettriggertime (note);

Alarmmanager alarm = (Alarmmanager) mcontext.getsystemservice (Context.alarm_service);

if (APILevel >= 19) {
LOG.D (TAG, "Alarm.set exact!");
Alarm.setexact (Alarmmanager.rtc_wakeup, Triggeratmillis, pendingintent);
} else {
LOG.D (TAG, "Alarm.set only");
Alarm.set (Alarmmanager.rtc_wakeup, Triggeratmillis, pendingintent);
}






Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Alarmmanager Alarm Delay response

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.