[Android Pro] Some questions about broadcast as an internal class when registering

Source: Internet
Author: User

Often broadcast is written as an internal class of activity or service. At this time the registration and ordinary a little bit different.

There are two cases 1, if the manifest file inside the static registration, you need to pay attention to. Ex:<application android:icon= "@drawable/ic_launcher" android:label= "@string/app_name" Android:them E= "@style/apptheme" > <receiver android:name= ". Myactivity$myreceiver "> <intent-filter> <action android:name="Com.example.test.BROADCAST "/></intent-filter> </receiver> </application> One of the key points. Myactivity$myreceiver Note that the class name is separated from the name of the inner class by the $ symbol. second, the action inside the name Com.example.test.BROADCAST when the distribution of this, when the broadcast sent Intent Intent = new Intent ("Com.example.test.BROADCAST"); Intent.putextra ("Action", "Test"); Sendbroadcast (Intent);be consistent with the parameters inside the intent. Otherwise, the broadcast will not be accepted. Third, public static class Myreceiver extends Broadcastreceiver do not forget to define the receiver as public static, or start will error. 2, if the dynamic registration is generally written in oncreate or OnStart methods such as intentfilter filter = new Intentfilter (Com.example.test.BROADCAST);Registerreceiver (Broadcastreceiver, filter), dynamic registration must start the program to accept the broadcast, static registration even if the program does not start, you can also receive the broadcast.

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.