Are there any time limits defined for actions run inside a BroadcastReceiver.onReceive method?
-
what do you mean with time limits? Usually BoradcastReceivers receive the broadcasts immediately... – Opiatefuchs Aug 08 '16 at 13:22
-
@Opiatefuchs you can see the details in CommonsWare answer. – VSB Aug 08 '16 at 13:49
1 Answers
onReceive()
is called on the main application thread, the same thread that drives your UI. In general, you want onReceive()
to return in under a millisecond, in case your UI is in the foreground, so you do not freeze the UI (a.k.a., have "jank"). There is also a 5-10 second limit, after which Android will basically crash your app.
However, you cannot reliably fork a background thread from onReceive()
, as once onReceive()
returns, your process might be terminated, if you are not in the foreground.
For a manifest-registered receiver, a typical pattern is to have onReceive()
delegate the work to an IntentService
, which has its own background thread and, being a service, tells the OS that your process is still doing some work and should let your process run a bit longer.

- 986,068
- 189
- 2,389
- 2,491
-
1As I checked [here](http://www.vogella.com/tutorials/AndroidBroadcastReceiver/article.html#asynchronous-processing) we can call goAsync() method for long running background task in broadcast receiver. May I have your comment on this? – VSB Aug 08 '16 at 13:48
-
1@VSB: I would rather use the `IntentService` approach. This is particularly true if you need to ensure that the device stays awake while you do your work, as the pattern for that involves a `WakefulBroadcastReceiver` and an `IntentService`. That being said, you are welcome to experiment with `goAsync()` if you wish. – CommonsWare Aug 08 '16 at 13:52
-
I've learned android from your `Android Programming Tutorials`. I had something on mind about this time limit from that time! – VSB Aug 08 '16 at 14:01
-
1Excellent solution to delegate work to `IntentService` from `BroadcastReceiver` – Kushal Oct 28 '16 at 10:54
-
For apps that targets android 12 or higher this is not possible, The android system limits app and app can not run service from broadcastReceiveer. App should run an expedited work. – David Sep 05 '22 at 05:52