1

I have some questions concerning wake lock and services

1- I try to test my service when the screen is off and not acquiring the wake lock, i was expecting that system will kill my service but it didn't happen, so what is the purpose of wake lock?

2- I want to know when then the system goes into doze mode, is it when i turn off the screen or after some time of turning it off? and what happens to my service in this case? and how to know that the system is in doze mode?

3- I know that since Android O normal background service will be killed after nearly one minute, i tried to test that by making intent service and make it running for more than one minute, it was already killed but started again and continued execution, so what is the purpose of killing it and starting it again?

4- does doze mode affect foreground service? and should i acquire wake lock in case of foreground service or is it acquired by default?

Code of Intent service

Logcat

I know they are lots of questions but i am confused with these topics

thanks in advance

amr
  • 63
  • 1
  • 7

1 Answers1

0
  1. The device may fall asleep if the user is inactive and nothing is keeping the device awake. A WakeLock is used to ensure the device stays awake.

You may check those links for additional information: Good answer Official Documentation

  1. Information about Doze mode, Standby and some other things that you may be interested in: link

  2. Background Service Limitations: While an app is idle, there are limits to its use of background services. This does not apply to foreground services, which are more noticeable to the user. link

  3. 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. link

--- Update ---

Some things could change from the moment of those questions were asked, so prefer to read documentation or search for the actual information about it. Also it's a good idea to check information about modern solutions for back ground like WorkManager.

Blind Kai
  • 514
  • 5
  • 14
  • first of all, thank you for your reply 1- for `PARTIAL_WAKE_LOCK` screen can be off and CPU is running, so `wake lock` does not necessarily block the screen, my question was why my service still works although i didn't acquire any wake lock and the screen is off 2- i don't understand what is the difference between normal off screen and doze 3- system killed my service and restarted it again, do you know why? – amr Aug 09 '19 at 18:05
  • @amr 3 - system doesn't kill and restart it. The point is, that the work is done in the separate thread and even if Service is destroyed it still can run in some cases and thread will finish all the work. – Blind Kai Aug 09 '19 at 19:51
  • How is this a solution to OP's question? – IgorGanapolsky Apr 10 '20 at 17:54