Android doze mode and foreground service

蹲街弑〆低调 提交于 2019-12-02 20:36:58

问题


I read many questions here about doze mode like Android doze mode, Android N Doze mode - how to keep background download and processing?, Wakelock and doze mode and many others. But in many replies, opinions is different. I can't test it by myself (emulator does not support my processor, and my only test device is android 5.1). I would like to know the next situation. I have an activity, which controls the media player. On devices with android 6.0 and higher it wouldn't work as expected cause of doze mode. As many solutions says to prevent doze mode it should start a service in separate process in foreground and control media player from there. The question is: if i start foreground service with partial wake lock in separate process, which would do nothing except showing notification, and leave controls to media player in my activity, should it prevent the doze mode? Or maybe there any other ways except keep the screen on from window manager?


回答1:


According to this SO question and answer:

In this post's comments on Sep 17 Dianne Hackborn writes:

Apps that have been running foreground services (with the associated notification) are not restricted by doze.

It looks like using a foreground service prevents the app from being killed by Doze.

Please note though, that some vendors (I know of Samsung, but there are probably others) create their own RAM conservation/battery saving tools. Not even caring about Doze. You are not guaranteed to get the same behaviour on these devices.



来源:https://stackoverflow.com/questions/44804432/android-doze-mode-and-foreground-service

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