Search code examples
androidandroid-broadcastreceiver

Android BroadCast Receiver runs in UI thread


My scenario is to fetch data from server and display it.

I am running a different process for fetching data from server but my app is hanging during download.

I use a broadcast receiver to send response from other process to UI thread.

I think BroadCastReceiver runs in UI thread? Am I doing anything wrong


Solution

  • Yes, the BroadcastReceivers method onReceive is running on the main thread, you can specify that it runs on a separate thread if you want, there is a method for that. The method is registerReceiver (BroadcastReceiver receiver, IntentFilter filter, String broadcastPermission, Handler scheduler)

    Check the docs of the onReceive() method for more info