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 ...
Get Pro Android 4 now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.