androidandroid-serviceandroid-doze

Doze mode - do foreground services continue to run?


im so confused reading this and trying to figure out if foreground services will run when the device goes into deep doze mode. Could someone clarify. I want to know on marshmallow and upwards if foreground services can continue to run. I always thought ALL THREADs are suspended even foreground services when device sleeps.

I see the doze mode restrictions but nothing about foreground services. im so confused if my services outlives doze mode security settings.

From what i can tell in the doze mode restrictions just network calls are stopped. But lets say i was doing some long running main thread work, it means it can continue to run right ? even in doze mode ?


Solution

  • Foreground services are not killed in doze mode and it's a great workaround to override the doze mode. Killing the foreground service is highly depending on Mobile OS. Like Huawei, it kills the foreground services after a slack of time and you will not be able to determine the period. Some other phones kill the oldest foreground service if it detects unexpected battery consumption. last year, I spent around 6 months observing phones behavior in killing the foreground services when doze mode is activated or not. and I tried more than one solution to override the doze mode in detecting location every 10 seconds and the best one is the foreground service. So you will face unexpected behavior on some phones but it is the best solution for doze and standby mode. You can see this article and you can also look at this tutorial