Android警报管理器正常运行,但延迟了

编程入门 行业动态 更新时间:2024-10-27 08:39:57
本文介绍了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警报管理器正常运行,但延迟了

本文发布于:2023-11-27 04:42:06,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1636639.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:管理器   警报   正常运行   Android

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!