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