Getting Started with Android Development (ii) Understanding intent objects using Intent 2.6

Source: Internet
Author: User

So far, you've learned how to use the intent object to invoke other activity. Next, let's say how the intent object is used.

1. You can pass an action to the constructor of the intent:

StartActivity (New Intent

("net.learn2develop.SecondActivity"));

2. You can specify the activity component directly, like this:

StartActivity (New Intent (This,secondactivity.class));

3. You can pass an action constant and data to the intent object:

Intent i = new Intent (Android.content.Intent.ACTION_VIEW, 

uri.parse ("http://www.amazon.com"));     
StartActivity (i);

The action section defines what you want to do, and the data section contains information that the target activity will perform. You can also pass data to a intent object by using the SetData () method:

Intent i = new Intent

("Android.intent.action.VIEW");     
I.setdata (Uri.parse ("http://www.amazon.com"));

The above example, through a specific URL, specifies the page you want to visit. The Android system will then look for activity that meets the requirements. This process is called "intent parsing."

For some intents, it is not necessary to set up data. For example, to pick a contact from a contacts application, you can set the action and use the Settype () method to set the MIME type:

Intent i = new Intent

(Android.content.Intent.ACTION_PICK);     
I.settype (ContactsContract.Contacts.CONTENT_TYPE);

The SetType () method explicitly specifies the MIME data type and also indicates the type of the returned data. The MIME type of the ContactsContract.Contacts.CONTENT_TYPE is "vnd.android.cursor.dir/contact".

In addition to specifying Action,data,type, a Intent object can also specify a category. Category the activities into "logical units" so that the Android system can use category for more "long-term" filtering. The next tutorial will talk about the category attribute in detail.

To sum up, a intent object can contain the following information:

Action

Type

Data

Category

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/OS/extra/

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.