Does BroadcastReceiver.onReceive always run in the UI thread?

后端 未结 5 1369
星月不相逢
星月不相逢 2020-11-28 02:35

In my App, I create a custom BroadcastReceiver and register it to my Context manually via Context.registerReceiver. I also have an AsyncTask<

5条回答
  •  臣服心动
    2020-11-28 03:23

    As the previous answers correctly stated onReceive will run on the thread it's registered with if the flavour of registerReceiver() that accepts a handler is called - otherwise on the main thread.

    Except if the receiver is registered with the LocalBroadcastManager and the broadcast is via sendBroadcastSync - where it will apparently run on the thread that calls sendBroadcastSync.

提交回复
热议问题