Android Intent (implicit)

Source: Internet
Author: User

Implicitly intent, the target component name is not explicitly indicated, as opposed to an explicit intent ( intent that explicitly indicates the target component name) . Explicit intent defines the target component directly with the name of the component, which is straightforward. But because developers often don't know the component names of other applications, explicit intent is more used to deliver messages inside the application. For example, within an application, an activity initiates a service. Implicit intent, on the contrary, does not define the target component that needs to be activated with the component name, which is more widely used to pass messages between different applications. In an explicit intent message, the only element that determines the target component is the component name, so if the name of the target component has been explicitly defined in intent, then no additional intent content is defined at all. For implicit intent, however, because there is no explicit target component name, the Android system must help the application find the component that best matches the intent of the intent request.

Implicit Intent specifies a series of more abstract actions and category information, which are then referred to the system for analysis. By configuring <intent-filter> on the <activity> tab, you can define the action and category for the current activity. Add an article to the Androidmanifest.xml:

<activity android:name=". Secondactivity">                        <intent-filter>                < Action android:name="com.example.myintent.ACTION_START"/>                <category android : Name="android.intent.category.MY_CATEGORY"/>            </intent-filter>                </activity>
Activity

Also modify the code in the mainactivity:

1  Public classMainactivity extends Activity {2     3     PrivateButton btn1;4 5 @Override6     protected voidonCreate (Bundle savedinstancestate) {7 super.oncreate (savedinstancestate);8 Setcontentview (r.layout.activity_main);9         Tenbtn1=(Button) Findviewbyid (r.id.button1); OneBtn1.setonclicklistener (NewOnclicklistener () { A              - @Override -              Public voidOnClick (View arg0) { the                 //TODO auto-generated Method Stub -                 //an explicit - //Intent intent=new Intent (mainactivity.this,secondactivity.class); - //startactivity (intent); +                  -                 //Implicit +Intent intent=NewIntent ("Com.example.myintent.ACTION_START"); AIntent.addcategory ("Android.intent.category.MY_CATEGORY"); at startactivity (intent); -             } -         }); -     } -  -      in}
OnClick

Only the action and category match at the same time, a intent can have only one action, but it may have multiple category. When the category is not added in <intet-filter>, the system will not error and will use the default category.

Android Intent (implicit)

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.