Broadcast send broadcast

① orderly broadcast: receiver a receives the broadcast and transmits it to B, and B transmits it to C for orderly transmission. Any link can terminate the broadcast or modify the data carried in the broadcast.

Sending method: sendorderedbroadcast (intent, receiverpermission);

[prompt] ① the second parameter is to set the sending permission, which can be set to null here

② to receive an ordered broadcast, you need to set priority in intent flter. The higher the value is, the higher the priority will be executed first. If the value is the same, the registration order will be followed

② disordered broadcast: a broadcast sender sends broadcasts to all receivers at the same time, that is, ABC receivers respond at the same time.

Sending method: sendbroadcast (intent)

① resident broadcast receiver: it is registered in Android manifest.xml. As long as the application is not uninstalled, it will continue to exist.

② non resident broadcast receiver: it is registered in Java code. It is generally generated with the generation of activity or service components and destroyed with their destruction. The life cycle is relatively short. The method used is registerreceiver (parameter 1: broadcast receiver instance, parameter 2: channel (intention filter)); Unregisterreceiver (broadcast receiver instance)

① define a broadcast receiver and add action name in intent fliter by user

② add button and click event

③ define intent, set action and send broadcast

[prompt] the action set by the sending broadcast intent should be the same as that set by the broadcast receiver, so that the broadcast receiver can receive the sent broadcast

① define three broadcast receivers and observe the sequence

② click the Add button

③ set intent to send an orderly broadcast

[prompt] set priority to different values and action name to the same value to receive the same broadcast

Click the button to execute the sequence

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>