Test the same priority of ordered Broadcast

Source: Internet
Author: User
Question: If two broadcastreceiver instances have the same priority, will the broadcast be received first?

Small test:

// On the main interface, click the button on the main interface to send an ordered Broadcast

Public class mainactivity extends activity {@ override public void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); setcontentview (R. layout. activity_main);} public void click (view) {// click the button to send an ordered broadcast intent = new intent (); intent. setaction ("CN. melon "); sendorderedbroadcast (intent, null );}}

// Myreceiver1. After receiving the broadcast information, print a Statement on the console, which is received by the receiver.

Public class myreceiver1 extends broadcastreceiver {@ overridepublic void onreceive (context, intent) {system. out. println ("myreceiver1 receives broadcast:" + intent. getaction ());}}

// Myreceiver2. After receiving the broadcast information, print a Statement on the console, which is received by the receiver.

Public class myreceiver2 extends broadcastreceiver {@ overridepublic void onreceive (context, intent) {system. out. println ("myreceiver2 received broadcast:" + intent. getaction ());}}

// Configure the main code of the configuration list

<receiver android:name=".MyReceiver2">            <intent-filter android:priority="1000">                <action android:name="cn.melon"/>            </intent-filter>        </receiver>        <receiver android:name=".MyReceiver1">            <intent-filter android:priority="1000">                <action android:name="cn.melon"/>            </intent-filter>        </receiver>

Result:

When two receive configurations are changed in the configuration list:

<receiver android:name=".MyReceiver1">            <intent-filter android:priority="1000">                <action android:name="cn.melon"/>            </intent-filter>        </receiver>        <receiver android:name=".MyReceiver2">            <intent-filter android:priority="1000">                <action android:name="cn.melon"/>            </intent-filter>        </receiver>

Result:

It is inferred that, when the priority is the same, the receiver first registers in the Android system and receives the broadcast first.

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.