Tutorial on getting started with Android (17th): Use Intent to call the "embedded" application Intent to analyze Intent

Source: Internet
Author: User

So far, we have learned how to use the Intent object to call other activities. Next, let's talk about how Intent objects are used.

1. You can pass an action to the Intent constructor:

[Java] startActivity (new Intent ("net. learn2develop. SecondActivity "));
StartActivity (new Intent ("net. learn2develop. SecondActivity"); 2. You can directly specify the Activity component, as shown in the following code:

[Java] startActivity (new Intent (this, SecondActivity. class ));
StartActivity (new Intent (this, SecondActivity. class); 3. You can pass an action constant and data to the Intent object:

[Java] Intent I = new Intent (android. content. Intent. ACTION_VIEW, Uri. parse ("http://www.amazon.com "));
StartActivity (I );
Intent I = new Intent (android. content. Intent. ACTION_VIEW, Uri. parse ("http://www.amazon.com "));
StartActivity (I); action defines "what do you want to do", and data includes the data to be executed by the target activity. You can also pass data to the Intent object through the setData () method:

[Java] Intent I = new Intent ("android. intent. action. VIEW ");
I. setData (Uri. parse ("http://www.amazon.com "));
Intent I = new Intent ("android. intent. action. VIEW ");
I. setData (Uri. parse ("http://www.amazon.com"); The above example specifies the page to be accessed through a specific URL. Then, the Android system looks for the activities that meet the requirements. This process is called "Intent Parsing ".

 


For some intents, there is no need to set data. For example, to select a contact from the Contacts application, you can set the action and use the setType () method to set the MIME type:

[Java] Intent I = new Intent (android. content. Intent. ACTION_PICK );
I. setType (ContactsContract. Contacts. CONTENT_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 returned data. The MIME type of ContactsContract. Contacts. CONTENT_TYPE is "vnd. android. cursor. dir/contact ".

In addition to specifying action, data, type, an Intent object, you can also specify a category. Category divides activities into "logical units", so that the Android system can use category for "long-term" filtering. The next tutorial will detail the category attributes.

To sum up, an Intent object can contain the following information:

Action
Type
Data
Category

 

From the column of horsttnann
 

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.