Radio plays a role in Android as a school horn.
Broadcasting is a kind of cross-process communication, which is divided into standard broadcast and orderly broadcast. Standard broadcast is a completely asynchronous broadcast, which is more efficient and means it will not be intercepted, and an ordered broadcast is a fully synchronous operation, and the broadcast receiver is orderly when it receives that type of broadcast, and has the right to intercept the broadcast.
Dynamic registration:
1> creates a broadcast receive class, inherits Broadcastreceiver, and overrides the parent class OnReceive method;
2> Monitor Filter:
Intentfilter intentfilter= new Intentfilter ();
Intentfilter.setaction ("Android.net.conn.CONNECTIVITY_CHANGE");
Networkrecvice = new Networkrecvice ();
Registerreceiver (Networkrecvice,intentfilter);
3> cancelling a broadcast
Unregistereceiver (Networkrecvice);
Static registration:
To register in Androidmanifest.xml:
<receiver
Android:name= ". Networkrecvice"
<intent-filter>
<action android:name= "Android.net.conn.CONNECTIVITY_CHANGE" >
<intent-filter>
</receiver>
Send an ordered broadcast:
Send broadcast:
Intent Intent = new Intent ("Android.net.conn.CONNECTIVITY_CHANGE");
Sendorderedbroadcast (Intent,null);
Set the priority level:
<receiver
Android:name= ". Networkrecvice"
<intent-filter android:priority= ">"
<action android:name= "Android.net.conn.CONNECTIVITY_CHANGE" >
<intent-filter>
</receiver>
Intercept broadcasts:
Abortbroadcast ();
Use local broadcast:
All broadcasts sent and received above belong to the system global broadcast, that is, the broadcast can be received by any other application, and can also accept broadcasts from any other program. To solve the security Jon Question, Android introduced the "Local broadcast system".
Registering and receiving local broadcasts differs little from system broadcasts, mainly because of the increased use of Localbroadcastmanager to manage broadcasts.
Send:
Localbroadcastmanager Manager = Localbroadcastmanager.getinstance (this);
.........
Manager.sendbroadcast (Intent);
The use of radio is relatively simple, the main master of its two different registration methods, according to the needs of specific applications.
Android Broadcast Basics