Learn about Android Broadcasts
Below is a summary of core knowledge points for the Android broadcast system:
1. Basic Concepts of the Broadcast System
- Real-world analogy: Similar to loudspeakers, radios and televisions, meaning “sent from one location and received by multiple locations”.
- Android mechanism: Provides a flexible broadcast messaging system. Each app may register for broadcasts it is interested in to receive only specific content.
- Broadcast sources: May come from the system (e.g. device boot, battery level changes) or from other applications.
- Sending and receiving: Broadcasts are normally sent via Intent; broadcast reception relies on BroadcastReceiver. Android offers a complete API set to freely send and receive broadcasts.
2. Types and Comparison of Broadcasts
Android broadcasts are mainly divided into Normal Broadcasts and Ordered Broadcasts. Their core differences are listed below:
| Comparison Item | Normal Broadcast | Ordered Broadcast |
|---|---|---|
| Execution Mode | Fully asynchronous | Synchronous sequential execution |
| Reception Timing | All receivers receive simultaneously once dispatched | Only one receiver receives at a time; the next runs only after processing completes |
| Order of Delivery | No defined order | Ordered delivery; receivers with higher priority get events first |
| Abort Mechanism | Cannot be aborted; all receivers will receive the broadcast | Earlier receivers may abort the broadcast, blocking subsequent receivers |
| Performance | High efficiency | Relatively slower (depends on delivery chain) |
3. Workflow Diagram Explanation
- Normal Broadcast
Broadcast sent→ Distributed concurrently toBroadcastReceiver 1,BroadcastReceiver 2,BroadcastReceiver 3(radial delivery, no interception). - Ordered Broadcast
Broadcast sent→BroadcastReceiver 1(may abort) →BroadcastReceiver 2(may abort) →BroadcastReceiver 3(linear delivery).