Android4.4 Framework Analysis--Broadcast registration (BROADCASTRECEIVER) and send (sendbroadcast) process analysis

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.