In the Android application framework, the activity and service classes inherit the Contextwrapper class, so we can call the Registerreceiver function in the activity or the service subclass to register the broadcast sink.
Is the process of registering a broadcast in the activity:
STEP1~STEP3, is the general invocation process.
The Step4,registerreceiverinternal () method is as follows:
Private Intent registerreceiverinternal (broadcastreceiver receiver, int userId, Intentfilter filter, String Broadcastpermission, Handler Scheduler, Context context) {Iintentreceiver rd = null; if (receiver! = null) {if (Mpackageinfo! = NULL && context! = null) {if (Scheduler = = NULL) {scheduler = Mmainthread.gethandler (); RD = Mpackageinfo.getreceiverdispatcher (receiver, context, scheduler, Mmainthread.getinstrumentation (), true); } else {if (scheduler = = null) {scheduler = Mmainthread.gethandler (); RD = new Loadedapk.receiverdispatcher (receiver, context, scheduler, NULL, true). g Etiintentreceiver (); }} try {return Activitymanagernative.getdefault (). Registerreceiver ( Mmainthread.getapplicationthread (), Mbasepackagename, RD, filter, broadcastpermission, userId); } catch (RemoteException e) {return null; } }
The Scheduler is Null,scheduler = Mmainthread.gethandler (), and the object of H is MH, which is used for subsequent broadcast transmission.
STEP6, first find out from the existing register list mreceivers whether by the same receiverdispatcher, if not previously registered, then new a receiverdispatcher, and recorded in Mreceivers, Receiverdispatcher during the creation process, a innerreceiver,innerreceiver is generated to receive the broadcast that the sendbroadcast sent over.
STEP9~STEP11, the broadcast receiver receiver is saved by using binder to access the registerreceiver of the Activitymanagerservice.
Is the process of broadcast sending (SENDBROADCAST):
Analysis Step Reference: http://blog.csdn.net/luoshengyang/article/details/6744448
Right-copy the image address and open it in the browser to see a larger image.
Please correct me if there is any wrong place to be continued.
Android4.4 Framework Analysis--Broadcast registration (BROADCASTRECEIVER) and send (sendbroadcast) process analysis