Extending IntentService for a Broadcast Receiver

From the perspective of a broadcast receiver, an IntentService is a wonderful thing. It lets us execute long-running code with out blocking the main thread. So can we use the IntentService for the needs of a long-running operation? Yes and no.

Yes, because the IntentService does two things: first, it keeps the process running because it is a service. And second, it lets the main thread go and avoids related ANR messages.

To understand the “no” answer, you need to understand wake locks a bit more. When a broadcast receiver is invoked, especially through an alarm manager, the device may not be on. So the alarm manager partially turns on the device (just enough to run the code without any UI) by making ...

Get Pro Android 4 now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.