Intents and Intent Filter

Understanding the Intent Object :
                                                            " So far, you have seen the use of the Intent object to call other activities. This is a good time to recap and gain a more detailed understanding of how the Intent object performs its magic."



First, you see that you can call another activity by passing its action to the constructor of an Intent
object:

         startActivity(new Intent(“net.learn2develop.ACTIVITY2”));


The action (in this example “net.learn2develop.ACTIVITY2”) is also known as the component name.
This is used to identify the target activity/application that you want to invoke. You can also rewrite
the component name by specifying the class name of the activity if it resides in your project, like this:

         startActivity(new Intent(this, Activity2.class));


You can also create an Intent object by passing in an action constant and data, such as the following:


         Intent i = new
         Intent(android.content.Intent.ACTION_VIEW,
         Uri.parse(“http://www.amazon.com”));
          startActivity(i);


The action portion defines what you want to do, while the data portion contains the data for the target
activity to act upon. You can also pass the data to the Intent object using the setData() method:

         Intent i = new
         Intent(android.content.Intent.ACTION_VIEW);
        i.setData(Uri.parse(“http://www.amazon.com”));

In this example, you indicate that you want to view a web page with the specified URL. The Android
OS will look for all activities that are able to satisfy your request. This process is known as intent
resolution. The next section discusses in more detail how your activities can be the target of other
activities.
For some intents, there is no need to specify the data. For example, to select a contact from the Contacts
application, you specify the action and then indicate the MIME type using the setType() method:

         Intent i = new
         Intent(android.content.Intent.ACTION_PICK);
         i.setType(ContactsContract.Contacts.CONTENT_TYPE);


The setType() method explicitly specifies the MIME data type to indicate the type of data to
return. The MIME type for ContactsContract.Contacts.CONTENT_TYPE is “vnd.android.cursor
.dir/contact”.


Besides specifying the action, the data, and the type, an Intent object can also specify a category. A
category groups activities into logical units so that Android can use it for further filtering. The next
section discusses categories in more details.

To summarize, an Intent object can contain the following information:

1. Action
2. Data
3. Type
4. Category