Type of broadcast:
1. Standard broadcast (normal broadcat)
Broadcasts that are executed completely asynchronously, all broadcast receivers receive broadcast messages at the same time.
High efficiency, but cannot be truncated.
2. Orderly Broadcasting
Simultaneous broadcast, only one broadcast receiver can receive broadcast messages at the same time, and will not continue to be delivered until the execution is complete.
High priority receives the broadcast first, and can truncate the broadcast.
Receive system broadcast:
Registration: Dynamic registration (code) and static registration (Androidamanifest.xml)
Dynamic Broadcast:
1. Inheriting Broadcastreceiver
2. Rewrite the OnReceive () method
3, Registered Registerreceiver ()
4, the dynamic registration of the broadcast receiver must be unregistered, unregisterreceiver ()
5, the Declaration of Rights in the Androidmanifest.xml
Static broadcast receivers are registered through the <receiver> tag in the Androidmanifest.xml,
<receiver android:name= ". Bootcompletereceiver ">
<intetn-filter>
<action android:name= "Android.intent.action.BOOT_COMPLETED" >//Start-up broadcast
</intent-filter>
</recevier>
Open threads are not allowed in the broadcast receiver, do not add too much logic, or take any time-consuming actions.
Custom broadcasts:
1. Standard Broadcast:
(1) Define a broadcast receiver
(2) Adding custom broadcast logic to the event
(3) Building the intent object, passing in the value of the broadcast to be sent
(4) Call the Sendbroadcast () method to send the broadcast
(5) <receiver> registration in Androidmanifest.xml
2. Orderly Broadcasting:
Basically, as with standard broadcasts, the Send call Sendorderedbroadcast () method.
Set priority in Androidmanifest.xml <intent-filter android:priority= ">"
Truncate broadcast call Abortbroadcast () method
Local broadcast: (addressing security issues)
Use Localbroadcastmanager to manage broadcasts.
(1) Get an example of him through Localbroadcastmanager.getinstance (this)
(2) Building Localreceiver class
(3) Dynamic registration via Localbroadcastmanager's Registerreceiver () method. The method contains 2 parameters Localreceiver and Intentfilter
(4) Call Localbroadcastmanager's Sendbroadcast () method to send the broadcast
(5) Cancellation of registration in the OnDestroy () method
Local broadcasts cannot be received by using static registration.
Broadcast broadcast Receiver