What I am hearing from this forum, the service might turn off as soon the device goes to asleep. Is that true?
Yes.
In my case, it works always
Then something else on your device is keeping the device from falling asleep. Perhaps use adb shell dumpsys power
to see what WakeLocks
are outstanding.
What is the need of WakeFulIntent Service? When do we need to use WakefulIntentService?
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. For transactional-type work (e.g., downloading a file), WakefulIntentService
combines an IntentService
and a WakeLock
to make keeping the device awake as long as necessary (and only as long as necessary) relatively easy.
WakefulIntentService
is not suitable for use with services that need to run indefinitely, such as a music player. For those, manage your own WakeLock
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…