Android Intents (Implicit, Explicit)

  Total Views : 88
  Comments : 0
  Keywords : Android intent is a message object that is passed between the components those are activities, content providers, broadcast receivers, etc., Android intents are the message objects

Here we will learn intents and intent filters in android with examples and how to use android intents and intent filters, different types of intents (explicit intents, implicit intents) with examples.

Android Intents

In android, Intent is a messaging object which is used to request an action from another app component such as activities, services, broadcast receivers and content providers.

 

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 type and intents are mainly useful to perform following things.

 

ComponentDescription
Starting an Activity By passing an Intent object to startActivity() method we can start a new Activity or existing Activity to perform required things.
Starting a Service By passing an Intent object to startService() method we can start a new Service or send required instructions to an existing Service.
Delivering a Broadcast By passing an Intent object to sendBroadcast() method we can deliver our messages to other app broadcast receivers.

Building an Intent Object

Generally, in android Intent object contains the information that required to determine which component to start and the information about the action to be performed by recipient component.

 

The Intent object in android is having a following characteristics to help android system to understand which component should start.

 

Component Name

 

It’s defines a name of the component to start and by using 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 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 an intent by using fully qualified class name of the target component and package name, for example com.tutlane.sampleActivity. We can set the component name by using setComponent(), setClass(), setClassName() or by using Intent constructor.

 

Action

 

It defines a name of the action to be performed to start an activity. Following are the some of common actions to start an activity.

 

ActionDescription
ACTION_VIEW We can use this action in an intent with startActivity(), when we have information that an activity can show to the user.
ACTION_SEND We can use this action in an intent with startActivity(), when we have a some data that the user can share through another app such as email app, social sharing app.

We can specify the action name of an intent by using setAction() or with an Intent constructor.

 

Data

 

It specify a type of the 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 android system to decide which is the best component to receive our intent.

 

Category

 

Generally, in android category is an optional for intents and it specify the additional information about type of the component that should handle an intent.

 

We can specify a category for an intent by using addCategory().

 

The above properties (Component Name, Action, Data and Category) will represent the characteristics of an intent. By using these properties, android system will easily decide which app component to start.

Android Intent Types

There are two types of intents available in android, those are Implicit Intents and Explicit Intents.

 

Different Types of Intents (Implicit, Explicit)

 

If you want to know about Implicit or Explicit intents check below URLS.

 

Android Implicit Intents with Examples

 

Android Explicit Intents with Examples

 

This is how we can use intents in android applications to invoke required service or an activity based on our requirements. 

 Comments (0)

Be the first to give your valuable feedback

Leave a comment

  • Default Tutlane User