简体   繁体   中英

When to acquire wakelock for an intent service?

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM