Differences between static and dynamic registration broadcasts

Source: Internet
Author: User

Differences between static and dynamic registration broadcasts

There are two types of broadcast receiver registration: static registration and dynamic registration.

The difference between the two and Their Broadcast Reception:

1. Dynamic Registration broadcast is always faster than static registration broadcast. No matter how high the static registration priority is, no matter how low the Dynamic Registration priority is> \

2. Dynamic Registration broadcast is not a resident broadcast, that is, the life cycle of the broadcast following the activity. Note: remove the broadcast receiver before the activity ends.

Static registration is resident, that is to say, when the application is closed, if information is broadcast, the program will be automatically run by the system call.

3. In the same priority, whoever starts fast first will receive the broadcast first.


Dynamic Registration Code:

UpdateBroadcast  broadcast= new UpdateBroadcast();IntentFilter filter = new IntentFilter("com.unit.UPDATE");registerReceiver(broadcast, filter);

Static registration code (added in the configuration file ):

<receiver android:name="net.youmi.android.AdReceiver" >            <intent-filter>                <action android:name="android.intent.action.PACKAGE_ADDED" />                <data android:scheme="package" />            </intent-filter> </receiver>




What is the difference between a dynamic website and a static website? What is the difference between dynamic websites and dynamic websites?

Simply put, a webpage that can interact with you is called a dynamic webpage. the webpage to be browsed is formed based on your input, such as registration. Every user on the registered page is different. dynamic Web pages are generally connected to databases. Based on your input, some parts of the database are extracted. the general Suffix of a dynamic web page is. asp ;. php ;. jsp, etc.

Why does Android dynamic broadcast receiver accept earlier than static broadcast receiver?

A broadcast receiver with the same priority dynamically registers earlier than a static one.
Dynamic Registration: static registration of the broadcast receiver registered by the Code: that is, in AndroidManifest. the priority of the broadcast receiver registered in xml: When the broadcast is sent in order, it is sent in this order. SendBroadcast sends unordered broadcasts. SendOrderedBroadcast sends ordered broadcasts. Now, looking for the cause of the problem, you must have this idea before looking for the cause. In an ordered queue, since the same priority is allowed, there will be sort sub-factors in the same priority, otherwise, the operation may affect the order. The latter is very likely. Open the source code, follow the Dynamic Registration of the broadcast receiver, and finally the ActivityManagerService. java file to find the registerReceiver implementation. You can also see that the stored broadcast receiver list is HashMap mRegisteredReceivers. There is a code in it: ReceiverList rl = (ReceiverList) mRegisteredReceivers. get (explorer. asBinder (); if (rl = null) {rl = new ReceiverList (this, callerApp, Binder. getCallingPid (), Binder. getCallingUid (), aggreger); if (rl. app! = Null) {rl. app. receivers. add (rl);} else {try {retry er. asBinder (). linkToDeath (rl, 0);} catch (RemoteException e) {return sticky;} rl. required todeath = true;} mRegisteredReceivers. put (aggreger. asBinder (), rl);} in it, find whether there is this handler, if not put in. It seems that the broadcast sequence is not processed here. Is there anything else to sort it? Look for a Member to change the logic and find a suspicious variable: final ArrayList mOrderedBroadcasts. That's right. It should be like it. Find only one mOrderedBroadcasts. set and extract the code: BroadcastRecord r = new BroadcastRecord (intent, callerApp,
CallerPackage, callingPid, callingUid, requiredPermission,
Sticky, false); mOrderedBroadcasts. set (I, r); put a BroadcastRecord object here, and the main thing in this object is actually the receivers tracking int NT = receivers! = Null? Receivers. size (): 0; int it = 0; ResolveInfo curt = null; BroadcastFilter curr = null; while (it <NT & ir <NR) {if (curt = null) {curt = (ResolveInfo) receivers. get (it) ;}if (curr = null) {curr = registeredReceivers. get (ir);} if (curr ...... remaining full text>

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.