The broadcast of Broadcastreceiver is divided into two categories: ordinary broadcast and orderly broadcast.
1. General Broadcasting:
by Context.sendbroadcast () or Sendstickybroadcast () method to send, all receivers receivers receive broadcast in an indeterminate order. This is more efficient, but broadcastreceiver cannot use the Setresult series, the GetResult series, and the Abort series API.
The intent emitted in sendbroadcast () is unacceptable when receveractivity is not in the Onresume state, even if it is later placed in that state. The Intent of Sendstickybroadcast () can be re-accepted to Intent when Receveractivity is onresume again. That's the Intent will being held to be Re-broadcast to the future receivers the expression of this sentence. That is, the last intent issued by Sendstickybroadcast will be preserved, and the next time Recevier is active, it will be accepted, and of course this intent can be removed by code.
2. Orderly Broadcasting:
is sent via Context.sendorderedbroadcast, and all receiver is executed sequentially. Broadcastreceiver can use the Setresult series function to pass the result to the next broadcastreceiver, through the GetResult series function to get the result of the previous broadcastreceiver return, And you can abort the series function to let the system discard the broadcast so that the use of the broadcast is no longer transmitted to other broadcastreceiver. You can set the priority of receiver by setting the Android:priority property in Intent-filter. Receiver with the same priority has an indeterminate order of execution. If Broadcastreceiver is registered in the code and its intent-filter has the same android:priority attribute, the first registration will receive the broadcast first.
========================================
-Each time the broadcast arrives, the Broadcastreceiver object is recreated, and the OnReceive () method is called, and the object is destroyed when it finishes executing. When the OnReceive () method does not complete in 10 seconds, Android will think that the program is unresponsive, so in the broadcastreceiver can not do some more time-consuming operation, the side will eject the ANR.
-If a time-consuming task needs to be completed, it should be done by sending Intent to the service, which can be sent by the service (Intentservice, as it runs on the child thread). It is not possible to use a child thread here, because the Broadcastreceiver life cycle is very short, the child threads may not be finished, Broadcastreceiver will be finished first, at this time broadcastreceiver The process is easy to kill when the system needs memory because it belongs to an empty process (assuming that the current process has no other active component). If its host process is killed, the working child thread is also killed, so it is unreliable to use a child thread to resolve it.
Broadcastreceiver the thing