Android from ignorance to knowing--no.8

Source: Internet
Author: User

The custom broadcast event mentioned in the previous article is out of order so that all broadcast receivers can receive the event, and we can also make the broadcast send in an orderly manner, which is similar to the former:

If the broadcast event is sent in order, the broadcast recipient receives sendorderedbroadcast (intent, NULL) in order of priority;//In an ordered broadcast, a high-priority recipient can terminate the broadcast event


This statement is similar to the out-of-order send, the first parameter is the specified "intent", the second is the permission to be added, which can be used first. The principle of sequential reception is high priority first receive, then receive by priority, we need to create two more files to test this function:

System.out.println ("Receiver1 received the broadcast"); Toast.maketext (Context, "1 detected a broadcast event", 1). Show ();

System.out.println ("Receiver2 received the broadcast"); Toast.maketext (Context, "2 detected a broadcast event", 1). Show ();

System.out.println ("Receiver3 received the broadcast"); Toast.maketext (Context, "3 detected a broadcast event", 1). Show ();


Then go to the list file to set their priority:

<receiver android:name= ". Mybro ">            <intent-filter android:priority=" >                <action android:name= "Com.heng.lh"/>            </intent-filter></receiver><receiver android:name= ". MyBro2 ">            <intent-filter android:priority=" >                <action android:name= "Com.heng.lh"/>            </intent-filter></receiver><receiver android:name= ". MyBro3 ">            <intent-filter android:priority=" >                <action android:name= "Com.heng.lh"/>            </intent-filter></receiver>


             In this way, when the status detection module sends broadcast events to the 3G module, MyBro3, MyBro2, and MyBro1 receive this broadcast event in turn.

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.