Android警报管理器正常运行,但延迟了 [英] Android Alarm manager working, but delayed

查看:69
本文介绍了Android警报管理器正常运行,但延迟了的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想给用户一个延迟(10分钟),然后,用户可以编辑一些内容。

I would like to make a delay(10 min) for user then after it, user can edit something.

为此,我创建了 setAlarm 函数:

public void setAlarm(Context context,int user,int time) {
   AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
   Intent intent = new Intent(context, sef_time.class);
   intent.putExtra(ONE_TIME, Boolean.FALSE);
   PendingIntent pi = PendingIntent.getBroadcast(context, 0, intent, 0);
   am.set(AlarmManager.RTC, 1000*60*time , pi); 
}

一切正常,但是我的警报管理器有一个延迟。
例如:

everything works fine, but my alarm manager has a delay. for example:

setAlarm(.....,int 10);

延迟时间:00: 10 03 秒或00: 10 10 秒00: 10 20 秒!

It has a delay : 00:10:03 second or 00:10:10 second 00:10:20 second !

我的错在哪里?

推荐答案

您可以看到此处


开头API 19,将传递给此方法的触发时间
视为 inexact :警报不会在此时间之前发送,但可能会延迟
并在以后发送。操作系统将使用此策略
来在整个系统中将警报批在一起,
最小化设备需要唤醒的次数,
最小化电池的使用。通常,只要在
将来的远处计划警报,就不会延迟在
以后的远期警报。

Beginning in API 19, the trigger time passed to this method is treated as inexact: the alarm will not be delivered before this time, but may be deferred and delivered some time later. The OS will use this policy in order to "batch" alarms together across the entire system, minimizing the number of times the device needs to "wake up" and minimizing battery use. In general, alarms scheduled in the near future will not be deferred as long as alarms scheduled far in the future.

使用新批次根据政策,交货订购担保的担保额不如之前的
。如果应用程序设置了多个
警报,则这些警报的实际交货顺序可能与
的请求交货时间顺序不匹配。如果您的
应用程序具有很强的订购要求,则可以使用
其他API来获得必要的行为;请参见setWindow(int,long,
long,PendingIntent)和setExact(int,long,PendingIntent)。

With the new batching policy, delivery ordering guarantees are not as strong as they were previously. If the application sets multiple alarms, it is possible that these alarms' actual delivery ordering may not match the order of their requested delivery times. If your application has strong ordering requirements there are other APIs that you can use to get the necessary behavior; see setWindow(int, long, long, PendingIntent) and setExact(int, long, PendingIntent).

targetSdkVersion在API 19之前的应用程序将继续
会获得以前的警报行为:所有计划的警报都将被
视为精确警报。

Applications whose targetSdkVersion is before API 19 will continue to get the previous alarm behavior: all of their scheduled alarms will be treated as exact.

如果要确保警报准确无误,请使用 setExact (当设备的SDK为19或更高版本时)。

If it's very important that the alarm be exact, use setExact (When the device's SDK is 19 or above).

这篇关于Android警报管理器正常运行,但延迟了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆