Shantnu Kumar
2 min readJul 13, 2021

--

Get to know about Intent and Intent filters

Let’s understand about Intents first.

As an Android developer, you must have used Intents to go to another activity and maybe passing some data along with it. Activity is one of the four components in Android, other three being Services, Broadcast Receivers and Content Providers. In the above scenario, we dealt with launching different activity with an Intent. So intent kind of acted as a messaging object that asked another activity to launch itself.

Briefly, we can describe intents as messaging objects that request some action from another app component (Activity in our example)

Type of Intents

  1. Explicit Intents
  2. Implicit Intents

A) Explicit Intents

Explicit Intents as the name suggest takes specific component’s name that it wants to start. For example, say we want to launch ActivityDestination from ActivitySource. Steps to launch the activity via intent is

Important point about explicit intents is that the communication happens between components of the same app.

B) Implicit Intents

In short, we specify the task we need to do and then android takes care of how to perform it. Let’s understand few components that will be useful to understand this better.

Let’s understand few terms to understand how this works?

Intent-filters — This is used by the components to specify which kind of intents it can respond to. For example, an app, A contains an intent filter for action “send” with type “text”, i.e the app facilitates sending textual data. Now another app B wants to send a text message. In case of implicit intent, android will compare the content of the intent with every app’s manifest file for the intent-filter with action “send” and type “text/plain”. Apps that satisfy the above check will be able to send the message that app A wants to. If there are multiple apps that can send it, the system will prompt a dialog with all the options and the user needs to decide which app to use else if there is only one app that can do the task, it will directly open without any action from our side.

Let’s take a scenario -

Suppose you click a picture and want to share it with your friends. You tap on share and android presents a lot of options like share via — Whatsapp, Gmail, Telegram, etc to name a few.

So we can say that these apps have the ability to share images (used intent-filters with type) and that’s why android responded with all the options to select from.

Steps to trigger implicit intent is -

We attempted to send a text message and let android decide which app it has to use to perform the action.

This marks an end to our discussion about intents and intent-filters. You can find the code here and try to run and see how it works. If you have any questions, feel free to comment. Thanks for reading!

--

--