Detailed introduction to Android broadcast receiving mechanism (with SMS receiving Implementation)

Detailed explanation of broadcast receiver in Android

1. Registration process of broadcastreceiver: (1) after the broadcast message is sent, only the object subscribed to the broadcast will receive the broadcast message and make corresponding processing** (2) . * * Android broadcasting is divided into two aspects: Broadcast sender and broadcast receiver. Broadcast in Android uses observer mode and message based publish / subscribe event model. The broadcast receiver registers with AMS through the binder mechanism. AMS finds the broadcastreceiver that meets the corresponding conditions and sends the broadcast to the corresponding message loop queue of broadcastreceiver (generally activity). When the message loop gets this broadcast, it calls back the onReceive () method in the broadcastreceiver. (3) The execution sequence of the broadcast sender and the broadcast receiver is asynchronous. The broadcast sent will not care whether there is a receiver or not, and it is uncertain when the receiver can receive it. 2. Steps of broadcastreceiver: (1) register broadcast: the broadcast receiver registers the broadcast in AMS. (2) . send broadcast: the broadcast sender sends a broadcast to AMS. (3) receive broadcast: the broadcast receiver executes the onReceive () method after receiving the broadcast.

The following is an example of sending SMS. The code is as follows:

Mainactivity class:

Note: the following permissions need to be added:

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
分享
二维码
< <上一篇
下一篇>>