0

From everything I read, by default, a Service should stop running after the phone is in sleep mode. This is what I want, but for some reason, the Service is continuing to run when the phone is sleeping. I am starting it with the startService in my app's only activity. How can I make my service stop when my phone is sleeping and then start back up when the phone is turned back on?

SpyMachine
  • 470
  • 1
  • 7
  • 17
  • Android decides if the Service needs to be killed or not. If you didn't call startForeground from your Service, it should be stopped when phones sleeps. – m0skit0 Jan 25 '15 at 20:33
  • Please note that closing your screen and sending the device to sleep are two different things. Especially if wake locks are involved. – Oren Jan 25 '15 at 20:39
  • @m0skit0 - I am not calling startForeground just startService. – SpyMachine Jan 25 '15 at 20:49
  • @Oren - I am not doing anything with wake locks. The only thing I have involving the Service is a checkbox which starts the service when it is checked and stops the service when it is unchecked. If the phone isn't "sleeping" when I shut off the screen, how can I make the service stop when the screen is shut off? – SpyMachine Jan 25 '15 at 20:51
  • Then you have to detect the screen lock and handle appropriately http://stackoverflow.com/questions/3170563/android-detect-phone-lock-event – m0skit0 Jan 25 '15 at 21:16
  • How do you know the service is still running, and not suspended along with everything else until wakeup? Most of the more trivial mechanisms you could use to determine that will themselves keep the phone awake. – Chris Stratton Jan 25 '15 at 22:55
  • Well I have the phone connected to Eclipse and the service is producing logcat results even when the screen is off. Plus, my service gradually makes changes which continue even when the screen is off. – SpyMachine Jan 26 '15 at 11:40

0 Answers0