Generally, in android, Intents will help us to maintain the communication between app components from the same application as well as with the components of other applications.
In android, Intents are the objects of android.content.Intent types and intents are mainly useful to perform the following things.
|Starting an Activity||By sending an Intent object to
|Starting a Service||By sending an Intent object to
|Delivering a Broadcast||By sending an Intent object to
Generally, in android Intent object contains the information required to determine which component to start and the information about the action to be performed by the recipient component.
The Intent object in android is having following characteristics to help the android system to understand which component should start.
It defines the name of the component to start and by using the component name android system will deliver intent to the specific app component defined by the component name. In case if we didn’t define component name then the android system will decide which component should receive intent based on other intent information such as action, data, etc.
In android, we can specify the component name for intent by using a fully qualified class name of the target component and package name, for example, com.tutlane.sampleActivity. We can set the component name by using
setClassName() or by using the Intent constructor.
It defines the name of the action to be performed to start an activity. The following are some of the common actions to start an activity.
|ACTION_VIEW||We can use this action in intent with
|ACTION_SEND||We can use this action in intent with
We can specify the action name of intent by using
setAction() or with an Intent constructor.
It specifies a type of data to an intent filter. When we create an intent, it’s important to specify the type of data (MIME type) in addition to its URI. By specifying a MIME type of data, it helps the android system to decide which is the best component to receive our intent.
Generally, the android category is optional for intents and it specifies the additional information about the type of component that should handle an intent.
We can specify a category for intent by using
The above properties (Component Name, Action, Data, and Category) will represent the characteristics of an intent. By using these properties, the android system will easily decide which app component to start.
There are two types of intents available in android, those are Implicit Intents and Explicit Intents.
If you want to know about Implicit or Explicit intents check below URLs.
This is how we can use intents in android applications to invoke the required service or activity based on our requirements.