Android Question Startserviceat during sleep

fransvlaarhoven

Active Member
Licensed User
Longtime User
Hallo,

I have a foreground service that reschedules itself using StartServiceAt("", RestartAt, True)

This works fine with a lot of different devices.

However, it seems to be that some android implementations go into some kind of deep sleep mode that just ignores the scheduled restart of the service.

I also experimented with phonewakestate but nothing seems to avoid this problem.

Do you have a suggestion how to solve this problem?
 

marcick

Well-Known Member
Licensed User
Longtime User
Here is explained how to use adb to force doze mode, so it should be easier to make test without waiting for "certain" times

https://developer.android.com/training/monitoring-device-state/doze-standby.html

Using these commands to force doze mode, it seems the whitelist works as we want.
I need to test the standby mode now.

B4X:
$ adb shell dumpsys battery unplug
$ adb shell dumpsys deviceidle step
You may need to run the second command more than once. Repeat it until the device state changes to idle.
 
Last edited:
Upvote 0

marcick

Well-Known Member
Licensed User
Longtime User
What a big trouble with this Android 6 ....
Playing with adb I'm now at this conclusion:

With StartForeground and acquiring a PartialLock, your service will run (with no precise timing) also when the device enter the doze mode, but it's probably unuseful in most cases because in doze mode the internet connection is locked.
To grant the internet connection in doze mode your app must be in the whitelist. So the app, more or less, will continue to work as in Android 5, but anyway the service timing are not respected and we can forget to do something every 30 seconds or so.

The only solution to fully wake up the device from any low-consumption mode, is to use the high-priority GCM messages.

To study further for my best solution, I would need help from the forum to implement these three cases:

 
Upvote 0
Top