0

Can someone please help me understand the following from the documentation?

For onReceive

This method is always called within the main thread of its process, unless you explicitly asked for it to be scheduled on a different thread using registerReceiver(BroadcastReceiver, IntentFilter, String, android.os.Handler). When it runs on the main thread you should never perform long-running operations in it

The following code:

IntentFilter filter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION);   
BroadcastReceiver receiver = new BroadcastReceiver() {    
    @Override
    public void onReceive(Context context, final Intent intent) {  
        if(Looper.myLooper() == Looper.getMainLooper()) {  
            Log.d(TAG, "Running in UI thread!");
        }    
    }    
};  
registerReceiver(receiver, filter);   

Always prints that it is running in the UI thread.
Is that not always the case?

Jim
  • 18,826
  • 34
  • 135
  • 254

0 Answers0