Chapter 5: Global Loudspeaker-Detailed Broadcasting Mechanism

A broadcast of one of the four major components of the Android system.

Broadcast classification

Broadcasting is divided into two categories:

  1. standard broadcast
  2. Ordered broadcast (ordered based on priority)

The broadcast will be chained, and the transmission can be terminated in the middle of the chain.

Classification of broadcast registration methods

There are two types of broadcast registration methods:

  1. Dynamic registration (that is, the code is dynamically registered in the program, this registration method will only take effect when the application starts)
  2. Static registration (this registration method is more powerful, and it will take effect even if the program is not started)

local broadcast

The broadcasts mentioned above are all global broadcasts, that is, cross-application communication is realized. However, this will also cause some insecurity factors, so there is another kind of broadcast that belongs to the local broadcast, and the broadcast transmitter and receiver are only valid in the same application.

important point

To receive some system broadcasts (such as start-up completion broadcasts, network status change broadcasts, etc.) requires the application to set corresponding permissions. How to set it up? Just declare the permissions in the AndroidManifest.xml file:

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

source code

See the source code:

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324765552&siteId=291194637