How does doze mode affect background/foreground services, with/without partial/full wakelocks?
Processes which have a current running foreground service are supposed to be unaffected by Doze. Bound/unbound, started/not-started, and wakelocks do not affect this whitelisting process.
However, there is an issue on Android M devices where foreground services are not properly whitelisted when the foreground service is the in the same process as the top activity and improperly dozed.
The fix is available on AOSP and will be included in builds of Android N. It would be up to OEMs to integrate that patch into any Android M builds they produce.
Keep ForegroundService alive When in Doze Mode
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.
Doze mode - do foreground services continue to run?
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
Doze mode and foreground service
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.
So yes, your findings seem to be the intended behavior.
Will foreground service work in not wake-up time of doze mode
I have an experience of my foreground service (with a notification that keeps updating every second) getting paused because of doze mode. I was running a timer function in my foreground service. When I came back after a long time, the timer wasn't really running because the device went doze mode. I had to request a WakeLock
to keep my service alive.
Starting foreground service in doze mode
you should use GcmTaskService. You can schedule some interval for your operations and it would work fine even in doze mode, check more information by link
Related Topics
How to Iterate Through a View's Elements
Cursorloader Not Updating After Data Change
How to Use the Android Accelerometer
Calculate the Size of a List View or How to Tell It to Fully Expand
Create Custom Big Notifications
Android - Print Full Exception Backtrace to Log
Cordova Plugin Development - Adding Aar
Displaying Yuv Image in Android
Live Audio Recording and Playing in Android and Thread & Callback Handling
Error:(9, 5) Error: Resource Android:Attr/Dialogcornerradius Not Found
Failure [Install_Failed_Invalid_Apk]
Sms Delivery Report in Android
How to Close All the Activities of My Application
Load the Image Saved in Sdcard in Webview
How to Measure Textview Height Based on Device Width and Font Size
Position of Dialogfragment in Android
Error:Execution Failed for Task ':App:Transformclasseswithdexfordebug' in Android Studio