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/