General broadcast
- Pros and Cons: Contrary to the pros and cons of ordered broadcasts!
- How to send a broadcast: Sendbroadcast ()
Orderly broadcast
- Advantages and Disadvantages
Pros: 1, priority receiver can process the data and pass it to the next receiver, depending on the priority
2, the transmission of broadcasting can be terminated by abortbroadcast
Cons: Low efficiency
- How to send a broadcast: Sendorderedbroadcast ()
- Receivers receiving broadcast first receive the processing result in broadcast via the Setresultextras (bundle) method, and the next receiver passes the bundle Bundle=getresultextras (true) method to get the data from the previous receiver.
Engineering
Mainactivity.java is a program to live import.
Mybroadcastreceiver.java and so on are broadcast receivers, but the level is not the same.
Finalrecevier.java is an orderly broadcast, even if the broadcast is intercepted, this can still receive the broadcast.
<receiverAndroid:name=". Mybroadcastreceiver "> <Intent-filterandroid:priority= "+"> <ActionAndroid:name= "Com.yydcdut.nima"/> </Intent-filter> </receiver> <receiverAndroid:name=". MyBroadcastReceiver2 "> <Intent-filterandroid:priority= "+"> <ActionAndroid:name= "Com.yydcdut.nima"/> </Intent-filter> </receiver> <receiverAndroid:name=". MyBroadcastReceiver3 "> <Intent-filterandroid:priority= "Ten"> <ActionAndroid:name= "Com.yydcdut.nima"/> </Intent-filter> </receiver> <receiverAndroid:name=". Finalrecevier "> <Intent-filter> <ActionAndroid:name= "Com.yydcdut.nima"/> </Intent-filter> </receiver>
In Mybroadcastreceiver.java, the code is the same:
Public class extends broadcastreceiver { @Override publicvoid onreceive (context context, Intent Intent) { System.out.println ("MyBroadcastReceiver1111111 received broadcast"); " Mybroadcastreceiver ", Toast.length_short). Show (); }}
In the Mainactivity.java:
Public classMainactivityextendsActivity {@Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Setcontentview (R.layout.activity_main); } Public voidClick (View view) {Intent Intent=NewIntent (); Intent.setaction ("Com.yydcdut.nima"); //Shuffle broadcastSendbroadcast (Intent); //Orderly Broadcast//sendorderedbroadcast (intent, NULL); //sendorderedbroadcast (Intent, NULL, New Finalrecevier (), NULL, 0, NULL, NULL); }}
Join in a class that is received by a broadcast
Abortbroadcast ();
It was to intercept the radio, but Finalrecevier still received it, no matter how the radio was intercepted.
I'm the dividing line of the king of the Land Tiger.
Source code: HTTP://PAN.BAIDU.COM/S/1DD1QX01
Broadcast send. zip
Reprint Please specify source: Http://www.cnblogs.com/yydcdut