栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

'setExact'和'setAlarmClock'之间的区别

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

'setExact'和'setAlarmClock'之间的区别

setExact()
setAlarmClock()
都作出非常类似的电话
setImpl()
。如果
RTC_WAKEUP
用于
setExact()
呼叫,则唯一的区别是type的最终arg
AlarmClockInfo

在服务端,该调用在set()中接收。在该方法的最后,我们可以看到额外参数带来的不同:

@Overridepublic void set(int type, long triggerAtTime, long windowLength, long interval, int flags,        PendingIntent operation, WorkSource workSource,        AlarmManager.AlarmClockInfo alarmClock) {    final int callingUid = Binder.getCallingUid();    if (workSource != null) {        getContext().enforcePermission(     android.Manifest.permission.UPDATe_DEVICE_STATS,     Binder.getCallingPid(), callingUid, "AlarmManager.set");    }    // No incoming callers can request either WAKE_FROM_IDLE or    // ALLOW_WHILE_IDLE_UNRESTRICTED -- we will apply those later as appropriate.    flags &= ~(AlarmManager.FLAG_WAKE_FROM_IDLE | AlarmManager.FLAG_ALLOW_WHILE_IDLE_UNRESTRICTED);    // only the system can use FLAG_IDLE_UNTIL -- this is used to tell the alarm    // manager when to come out of idle mode, which is only for DeviceIdleController.    if (callingUid != Process.SYSTEM_UID) {        flags &= ~AlarmManager.FLAG_IDLE_UNTIL;    }    // If the caller is a core system component, and not calling to do work on behalf    // of someone else, then always set ALLOW_WHILE_IDLE_UNRESTRICTED.  This means we    // will allow these alarms to go off as normal even while idle, with no timing    // restrictions.    if (callingUid < Process.FIRST_APPLICATION_UID && workSource == null) {        flags |= AlarmManager.FLAG_ALLOW_WHILE_IDLE_UNRESTRICTED;    }    // If this is an exact time alarm, then it can't be batched with other alarms.    if (windowLength == AlarmManager.WINDOW_EXACT) {        flags |= AlarmManager.FLAG_STANDALONE;    }    // If this alarm is for an alarm clock, then it must be standalone and we will    // use it to wake early from idle if needed.    if (alarmClock != null) {        flags |= AlarmManager.FLAG_WAKE_FROM_IDLE | AlarmManager.FLAG_STANDALONE;    }    setImpl(type, triggerAtTime, windowLength, interval, operation, flags, workSource, alarmClock, callingUid);}

如果存在非null

alarmClock
参数,则请求会
FLAG_WAKE_FROM_IDLE
在的顶部获得标志,
FLAG_STANDALONE
在两种情况下都会获得该标志。的评论为
FLAG_WAKE_FROM_IDLE

警报标记:即使设备处于空闲状态,此警报也要唤醒设备。例如,这是用于闹钟的警报。

如果需要,您可以深入了解-
的用法

FLAG_WAKE_FROM_IDLE

,据我所知,就是这样。您的“正常”确切警报不会将设备从空闲状态唤醒,但是使用setAlarmClock()设置的警报会唤醒。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/569499.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号