O'Reilly logo

Pro Android 4 by Satya Komatineni, Dave MacLean

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required