2

If I start a service with "START_STICKY" mode (android was awake when this service was started), does this make sure that the service will keep running (in the sleep mode / prevent android from sleeping) even if the screen is off and the device is not plugged in?

In other words, once a service is started in "START_STICKY" mode, is it required to acquire a wake lock to make sure android doesn't sleep? Or, is it guaranteed that once such a service is started, android will not sleep until the service is stopped by the app?

Mohit Singh
  • 1,452
  • 1
  • 18
  • 27
  • read this document to learn more about it. http://developer.android.com/reference/android/app/Service.html#START_STICKY – Vivek Mishra Jan 21 '16 at 11:13

1 Answers1

4

does this make sure that the service will keep running (in the sleep mode / prevent android from sleeping) even if the screen is off and the device is not plugged in?

No.

is it required to acquire a wake lock to make sure android doesn't sleep?

Yes.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Thanks for the swift reply Mark! Actually when I started a media player with this service, and the song was set to loop, I waited for entire hour with the screen off, and the song was still playing. So I thought maybe, that was the case. (no other wake locks from my app). – Mohit Singh Jan 21 '16 at 11:34
  • 2
    @MohitSingh: No, `START_STICKY` only says "restart my process after you terminate it". Something else may be holding a `WakeLock`. **`adb shell dumpsys power**` should tell you: http://stackoverflow.com/questions/5780280/how-can-i-see-which-wakelocks-are-active – CommonsWare Jan 21 '16 at 11:59
  • Thanks again, this will really help me :) – Mohit Singh Jan 21 '16 at 12:10
  • by the way, I just confirmed it - it says this while the track plays: `Wake Locks: size=1 PARTIAL_WAKE_LOCK 'AudioMix' (uid=1013, pid=0, ws=WorkSource{10107})` – Mohit Singh Jan 21 '16 at 12:25
  • 2
    @MohitSingh: It's possible that comes from the media playback. You might try commenting that bit out, terminate your existing process, confirm that you're not associated with a `WakeLock`, then run the revised app. – CommonsWare Jan 21 '16 at 12:32