Android registered Broadcasting and its pros and cons

Source: Internet
Author: User

Under Android, to receive broadcast information, the broadcast receiver will have to be implemented by ourselves, and we can inherit broadcastreceiver and we can have a broadcast receiver. A receiver is not enough, we have to rewrite the broadcastreceiver inside the Onreceiver method, and then register the broadcast

There are two methods, one is code dynamic registration:

Generate broadcast Processing
Smsbroadcastreceiver = new Smsbroadcastreceiver ();
Instantiate the filter and set the broadcast to filter

Intentfilter intentfilter = new Intentfilter ("Android.provider.Telephony.SMS_RECEIVED");

Register for Broadcast
BroadCastReceiverActivity.this.registerReceiver (Smsbroadcastreceiver, Intentfilter);

The second is to configure the broadcast in Androidmanifest.xml

<!--broadcast registered-->  
        <receiver android:name= ". Smsbroadcastreceiver ">  
            <intent-filter android:priority=" >  
                <action android:name= " Android.provider.Telephony.SMS_RECEIVED "/>  
            </intent-filter>  
        </receiver>        

The difference between the two registration types is:

1 The first is not resident type broadcasts, that is, the broadcast follows the life cycle of the program.

2 The second is a resident type, which means that when an application shuts down, the program is automatically run by the system call if there is information broadcast.

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.