When to acquire wakelock for an intent service?

742 views Asked by At

I am trying to understand the use of partial wake locks in android. I have a wakeful intent service which starts another intent service.

If I don't acquire a wakelock for the called intent service, the intents will be processed when the CPU wakes up? Is there any scenario where these intents are not processed at all?

1

There are 1 answers

0
ctate On

If you call startService() [whether directly or by calling send() on a service PendingIntent], it starts up the OS's process of spinning up that service. The device going to sleep in the middle won't interrupt that process; it will just delay it until the device is awake and running long enough to finish the process of starting up the service you requested.

The only time the service will never start is if there is something wrong with the startService() request itself -- the Intent does not resolve to a real Service definition, or you don't have permission to start that service, or something like that. None of these failure modes have anything to do with wakelocks, though. The wakelock situation won't cause startService() to fail outright.