The custom broadcast event mentioned in the previous article is out of order so that all broadcast receivers can receive the event, and we can also make the broadcast send in an orderly manner, which is similar to the former:
If the broadcast event is sent in order, the broadcast recipient receives sendorderedbroadcast (intent, NULL) in order of priority;//In an ordered broadcast, a high-priority recipient can terminate the broadcast event
This statement is similar to the out-of-order send, the first parameter is the specified "intent", the second is the permission to be added, which can be used first. The principle of sequential reception is high priority first receive, then receive by priority, we need to create two more files to test this function:
System.out.println ("Receiver1 received the broadcast"); Toast.maketext (Context, "1 detected a broadcast event", 1). Show ();
System.out.println ("Receiver2 received the broadcast"); Toast.maketext (Context, "2 detected a broadcast event", 1). Show ();
System.out.println ("Receiver3 received the broadcast"); Toast.maketext (Context, "3 detected a broadcast event", 1). Show ();
Then go to the list file to set their priority:
<receiver android:name= ". Mybro "> <intent-filter android:priority=" > <action android:name= "Com.heng.lh"/> </intent-filter></receiver><receiver android:name= ". MyBro2 "> <intent-filter android:priority=" > <action android:name= "Com.heng.lh"/> </intent-filter></receiver><receiver android:name= ". MyBro3 "> <intent-filter android:priority=" > <action android:name= "Com.heng.lh"/> </intent-filter></receiver>
In this way, when the status detection module sends broadcast events to the 3G module, MyBro3, MyBro2, and MyBro1 receive this broadcast event in turn.