Doze模式调试下AlarmManager后台运行问题
来源:互联网 发布:周柏豪性格知乎 编辑:程序博客网 时间:2024/05/20 12:22
最近在android7.0平台下,调试在Doze模式下长连接运行状态。
从6.0开始android便加入了低耗电模式,此模式下限制了很多行为,包括我们时常用到的AlarmManager的行为限制。而对于进入Doze模式7.0去除了6.0的静止状态的条件,因此进入Doze模式比6.0更加容易
The following restrictions apply to your apps while in Doze:
- Network access is suspended.
- The system ignores wake locks.
- Standard
AlarmManager
alarms (includingsetExact()
andsetWindow()
) are deferred to the next maintenance window. - If you need to set alarms that fire while in Doze, use
setAndAllowWhileIdle()
orsetExactAndAllowWhileIdle()
. - Alarms set with
setAlarmClock()
continue to fire normally — the system exits Doze shortly before those alarms fire.
- If you need to set alarms that fire while in Doze, use
- The system does not perform Wi-Fi scans.
- The system does not allow sync adapters to run.
- The system does not allow
JobScheduler
to run.
setAndAllowWhileIdle()
和 setExactAndAllowWhileIdle()
于是先写个demo,Alarm每分钟发送一条广播,分别使用setExact()和setExactAndAllowWhileIdle()进行测试
adb 进入Doze模式
发现setExact()设置的Alarm,几乎不起作用了。只能等到下次的maintenance window了。
而setExactAndAllowWhileIdle()设置的Alarm,只发送了一条广播便停了,这个不急再继续看官网,
Note: Neither setAndAllowWhileIdle()
nor setExactAndAllowWhileIdle()
can fire alarms more than once per 9 minutes, per app.
意思是每9分钟只能起来一次了,于是继续等着,果然9分钟后,广播接收到了。
然后便开始测试长连接的状态,发现Alarm是正常使用的,并没有受到影响。
于是便想着把app和长连接一样配置为系统进程,源码下编译后从新测试,果然Alarm正常使用了。
总体来说对功耗要求越来越高的android,一般的app在 Doze模式下,只能按google要求,每9分钟只能起来一次Alarm了。
- Doze模式调试下AlarmManager后台运行问题
- Android Doze模式下的AlarmManager策略
- 关于Doze 模式下对AlarmManager 的影响
- Android Doze模式调试
- Android Doze模式分析
- Android7.0 Doze模式
- Android Doze模式
- Android 6.0 Doze模式
- Android doze模式分析
- Jboss 后台运行模式
- Android 7.0 Doze模式分析
- Android7.0 Doze模式流程
- linux下后台运行
- python 后台运行问题
- Android7.0 Doze模式分析(一)Doze介绍 & DeviceIdleController
- Android7.0 Doze模式分析 Doze介绍 & DeviceIdleController
- Android7.0 Doze模式分析(一)Doze介绍 & DeviceIdleController
- VC 调试模式下多线程的问题
- CMake error: error in configuration process, project files may be invalid
- 安卓解BUG方法
- 阿里云---新的短信服务(整合到消息服务MNS后)
- 数独问题
- 分化数小数
- Doze模式调试下AlarmManager后台运行问题
- java基础知识
- Java 抽象类、普通类、接口的区别——值得你一看的干货
- 62. Unique Paths
- 呼叫中心开发框架Asterisk
- Longest Palindromic Substring
- SSH和SSM对比总结
- python:序列
- 解决“ipheth_tx_timeout: TX timeout”