Search code examples
androidbroadcastreceiverlocalbroadcastmanager

LocalBroadcastManager order of execution


I am trying to understand how BroadcastReceivers work on Android. My question is, will there be a delay between the time I call sendBroadcast on a LocalBroadcastManager to the time it is received in my BroadcastReceiver? Will the call be synchronous?

For example, when invoking myFunction, will the output be 21 or 12??

myFunction {
  sendBroadcast;
  print "1";
}

myReceiver {
  print "2";
}

what if the function running is changed to

myFunction {
  sendBroadcast1;
  print "1";
  sendBroadcast2;
  callALotOfOtherFunctions;
}

myReceiver1 {
  print "2";
}

myReceiver2 {
  print "3";
}

will all the other functions called from myFunction be called before the receivers?


Solution

  • intents are being sent one after another, just like any event on the message queue.

    there is no delay, only waiting in line for your event/intent to be taken care of , since there might be other events/intent to be handled first.

    they are all being called on the UI thread, which loops over all of the events (and intents), therefore it's called the main looper thread.