Android9.0 BroadcastReceiver case analysis with source code

Android BroadcastReceiver is used for asynchronous inter-process communication. It is similar to the publish-subscribe design pattern. It does not have an interface like Activity. It is an Android component used to broadcast messages to the system or applications. This broadcast message refers to events or intent. Specific examples are notification of low power capacity of the system, notification of download, etc.
Commonly used system intents are:
android.intent.action.BATTERY_CHANGED
android.intent.action.BATTERY_LOW
android.intent.action.POWER_CONNECTED
android.intent.action.POWER_DISCONNECTED
android.intent.action.BOOT_COMPLETED
android.intent.action.CALL
android. intent.action.DATE_CHANGED
android.intent.action.REBOOT
android.intent.action.CONNECTIVITY_CHANGE
android.intent.action.BUG_REPORT
android.intent.action.CALL_BUTTON

There are roughly two types of broadcast messages in Android:
1. Orderly broadcast
2. Unordered broadcast

Sequential broadcast is a synchronous broadcast. Broadcast messages are sent in sequence, and the sequence numbers are arranged according to the android:priority attribute. Broadcast messages of the same priority will not be prioritized.
Out-of-order broadcast is asynchronous broadcast, which sends broadcast messages randomly, and uses Context:sendBroadcast to send broadcast messages.

To implement BroadcastReceiver, you first need to register the receiver.
There are two ways:
1. Register through Context

Guess you like

Origin blog.csdn.net/poolooloo/article/details/106833605