androidandroid-dozeandroid-doze-and-standby

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.


Solution

  • 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.