Intents and Intent Filters (Part 1)

Learn about intent objects and intent filters that Android apps use to pass messages between app components.

In Android, intents provide a powerful way for different app components to communicate with each other and interact with other apps. They can also provide messaging services between various app components. By using intents, an app can start new activities, broadcast messages to other apps, or access different types of data from different sources. Let’s explore intents and intent filters for the communication between various apps and within components of the same app.

Types of intents

The Android OS has two types of intents:

  • Explicit intents: We use these intents to start a system service or a component in the same app. They specify the name of the target app’s package or the name of the component class. For instance, following a user action, we can start a new activity within our app or start a system service in the background.

  • Implicit intents: We use these intents to specify an action to perform rather than specifying a component name. This permits components from other apps to handle such an intent. For instance, when we need to display a map location to the app user, we can use an implicit intent to request the apps that can show a map location.

In Android, the use of implicit intent to start a service isn’t safe because we aren’t sure which service is going to respond to the intent. Furthermore, services run in the background, and app users don’t know which service starts.

Note: For safety purposes, the Android OS doesn’t allow us to start any system service using an implicit intent.

We don’t declare intent filters for services and always use explicit intents to start system services.

Intent filters

...

Get hands-on with 1400+ tech skills courses.