Android广播接收过程
2023-06-21 本文已影响0人
在岁月中远行
广播如何注册,广播如何执行receiver方法的
我们普通的广播发送

最后调用的是

其中IItentReceiver是个aidl类,这个方法目的就是获取到rd,然后调用AMS的registerReceiver注册方法。

mRegisteredReceivers是一个final HashMap<IBinder,ReceiverList> mRegisteredReceivers =new HashMap<>(); key就是我们上面的IIntentReceiver,Value是ReceiverList。接下来我们看看这个类

这里面有ProcrssRecord进程的描述,pid:进程id,uid:用户id
一个APP进程有可能注册多个广播。
发送广播的过程其实就在将receiver保存到系统进程AMS的一个mRegistedReceivers(HashMap数据结构)中。
下面我们来分析发送广播:
从发送最简单最普通广播主要分析整个流程




将广播入队列(数据结构不是队列)和MessageQueue内部维护了一个数组而已。通过Handler发送一个BROADCAST_INTENT_MSG消息










最后看到这里就是回调了receiver的方法,这样整个接收广播的大概流程就走完了。