I am bit confused after going through the questions & answers in Stackoverflow about WakefulIntentService. I just would like to get some knowledge on this topics to make sure my understanding is correct, please feel free to correct me, if I am wrong.
I built a small application, where I am using a background Service that keeps playing music whenever the user shakes the mobile. I tested after the device is locked and screen is turned off and it works as expected.
-
What I am hearing from this forum, the service might turn off as soon the device goes to asleep. Is that true? In my case, it works always, Am I missing something?
-
What is the need of
WakeFulIntentService? When do we need to useWakefulIntentService? -
I tried running a timer in a
Service, though the device is locked and screen is turned off and my timer is running pretty much I can say for sure. Because I used to get notification whenever my timer trips.
Yes.
Then something else on your device is keeping the device from falling asleep. Perhaps use
adb shell dumpsys powerto see whatWakeLocksare outstanding.The device may fall asleep if the user is inactive and nothing is keeping the device awake. A
WakeLockis used to ensure the device stays awake. For transactional-type work (e.g., downloading a file),WakefulIntentServicecombines anIntentServiceand aWakeLockto make keeping the device awake as long as necessary (and only as long as necessary) relatively easy.WakefulIntentServiceis not suitable for use with services that need to run indefinitely, such as a music player. For those, manage your ownWakeLock.