Question: If two broadcastreceiver instances have the same priority, will the broadcast be received first?
Small test:
// On the main interface, click the button on the main interface to send an ordered Broadcast
Public class mainactivity extends activity {@ override public void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); setcontentview (R. layout. activity_main);} public void click (view) {// click the button to send an ordered broadcast intent = new intent (); intent. setaction ("CN. melon "); sendorderedbroadcast (intent, null );}}
// Myreceiver1. After receiving the broadcast information, print a Statement on the console, which is received by the receiver.
Public class myreceiver1 extends broadcastreceiver {@ overridepublic void onreceive (context, intent) {system. out. println ("myreceiver1 receives broadcast:" + intent. getaction ());}}
// Myreceiver2. After receiving the broadcast information, print a Statement on the console, which is received by the receiver.
Public class myreceiver2 extends broadcastreceiver {@ overridepublic void onreceive (context, intent) {system. out. println ("myreceiver2 received broadcast:" + intent. getaction ());}}
// Configure the main code of the configuration list
<receiver android:name=".MyReceiver2"> <intent-filter android:priority="1000"> <action android:name="cn.melon"/> </intent-filter> </receiver> <receiver android:name=".MyReceiver1"> <intent-filter android:priority="1000"> <action android:name="cn.melon"/> </intent-filter> </receiver>
Result:
When two receive configurations are changed in the configuration list:
<receiver android:name=".MyReceiver1"> <intent-filter android:priority="1000"> <action android:name="cn.melon"/> </intent-filter> </receiver> <receiver android:name=".MyReceiver2"> <intent-filter android:priority="1000"> <action android:name="cn.melon"/> </intent-filter> </receiver>
Result:
It is inferred that, when the priority is the same, the receiver first registers in the Android system and receives the broadcast first.