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

Long-Running Receivers and Services

So far, we have covered the happy path of broadcast receivers where the execution of a broadcast receiver is unlikely to take more than ten seconds. As it turns out, the problem space becomes a bit complicated if we want to perform tasks that take longer than ten seconds.

To understand why, let's quickly review a few facts about broadcast receivers:

  • A broadcast receiver, like other components of an Android process, runs on the main thread.
  • Holding up the code in a broadcast receiver will hold up the main thread and will result in ANR.
  • The time limit on a broadcast receiver is ten seconds compared to five seconds for an activity. It is a touch of a reprieve, but the limit is still there.
  • The process hosting ...

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