Android application consists of a collection of components such as activities,services.Our application may need to communicate with the functionality provided by other android applications.In such scenarios we can use the Intent to invoke the desired functionality.For example intent can be used to start another activity or consume a service.
Intent class is defined in the android.content package.
To invoke the requested functionality we use the intent object.To invoke the required functionality we follow the below
two steps:
- Create an object of Intent type.
- Invoke the startActivity() method and pass intent object created in step 1.
In the step 1 above we specify the following two pieces if information when creating an object of Intent:
- action The action to be performed.
- data The data to perform the action on.
In the following example we are creating an intent to start another activity
First we create an object of Intent type.
Intent i = new Intent(this, SampleActivity.class);
Here we are specifying that we want to execute the Activity called SampleAtivity.
Then we start the activity by calling the startActivity() method.
startActivity(i);
There are some common action types which you can use when creating an Intent:
- ACTION_VIEW display data to the user
- ACTION_DELETE deletes the specified data
- ACTION_OPEN_DOCUMENT for allowing user to select a document
- ACTION_MAIN Starts an activity as main activity
- ACTION_INSERT For inserting an item in container
Leave a Reply