Android M (preview) Doze mode and AlarmManager

只愿长相守 提交于 2019-12-10 13:33:54

问题


I'm trying to test the behavior of our Android app when the OS goes in Doze mode. I'm using an emulator running Android API 23 (Revision 1). The application launches a Service through the AlarmManager using the method setInexactRepeating with type ELAPSED_REALTIME_WAKEUP. I set the alarm to fire approximately every three minutes (only for testing purposes). After several attempts (the official guide is very unclear) I succeed to put the emulator in IDLE state by locking the screen of the emulator and running dumpsys suggested commands. When the device is IDLE I'm still able to see the Service being launched by the alarm. This should not be the expected behavior. I was expecting the Alarm be stopped. Is this a bug? Or am I missing something?


回答1:


For test use code below.

adb shell dumpsys deviceidle enable adb shell dumpsys battery unplug adb shell dumpsys deviceidle step adb shell dumpsys deviceidle force-idle

Use setAndAllowWhileIdle for force smartphone wakeup.

In my case I use this:

if (android.os.Build.VERSION.SDK_INT > 22) { am.setAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), sender); } else { am.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), AlarmManager.INTERVAL_DAY, sender); }

I believe that the expected is the Alarm be stopped.



来源:https://stackoverflow.com/questions/32904106/android-m-preview-doze-mode-and-alarmmanager

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!