简体   繁体   中英

Keep ForegroundService alive When in Doze Mode

Running foreground services doesn's prevent device from going to sleep. You must require a wakelock. Does this also apply in Doze mode?

For example: You run a foreground service and then turn the device's screen off. In general doze's mode restrictions don't apply in foreground services like network suspension etc.

So my question is, do you need to hold a wakelock for foreground services in doze mode?

I am a little bit confuse because doze mode ignores wakelocks unless if puts an exception to foreground services.

As per this , the following is a restriction which applies in doze mode :

The system ignores wake locks.

You still need to hold a wakelock "to indicate that your application needs to have the device stay on".

So, your wake lock will not affect doze mode (and that is by design). However, if you are using a foreground service, doze mode does not seem to affect foreground services see this SO post .

If you are using something else, you can see this guide here to optimize your app for doze mode.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM