Android Development Intent (1)

Source: Internet
Author: User

Intent can be used to launch components and carry data that acts as a medium for communication between components.

The intent object roughly contains component, Action, Category, Data, Type, Extra, and Flag7 properties.

The following will be said separately.

Component

Component can start specific components by specifying the package name and the class name. Therefore, intent, which explicitly specifies the component property, is also known as an explicit intent. Examples are as follows:

// Create a ComponentName object New ComponentName (fromactivity.  this,        toactivity. class  New  Intent (); // Set component property for intent intent.setcomponent (comp); startactivity (intent);

Because the package name corresponds to context one by one, the constructor for passing in the context parameter is also provided in ComponentName.

Action

as follows, set the action to "xxx", and if an activity contains code in Androidmanifest.xml that is shaped like code 2, you can start the activity with code 1. You can specify only one action per intent. In addition, if the category is not set, "Android.intent.category.DEFAULT" is used by default, so you need to join the <category in code 2 Android:name= "Android.intent.category.DEFAULT" />

Code 1

// Create a Intent object New Intent (); // set the Action property for intent (the property value is a normal string)intent.setaction ("xxx"); startactivity (intent);

Code 2

< Intent-filter >    <  android:name= "xxx"/>        <android:name  = "Android.intent.category.DEFAULT"/></intent-filter >

Category

Use Intent.addcategory ("xxx"), and then add <category android:name= "xxx" to Androidmanifest.xmlactivity's registration, using the same method as the action > can. Unlike action, a intent can contain multiple category values, and the intent can only initiate an activity that joins all the category values that the intent contains at the time of registration.

Android Development Intent (1)

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.