Android IPC — Intents

Sudheer
3 min readJun 22, 2021

These are some of notes regarding Android Intents.

What are Intents?

Messaging objects to request action from another app component.

Use cases

  1. Starting an activity — passing an intent that describes the activity and associated data needed to startActivity(). Results are also received back from the call over an Intent
  2. Starting a Service — Services run in the background (without a UI). For API Level 25 and prior: invoke startService() with intent describing the service to start and any data needed. API Level 26 and later, use the JobScheduler APIs.
  3. Broadcasts — to specify the action and any associated data.

Types

  1. Explicit Intent: specify the app/component that will satisfy the intent. Specify the package name or fully qualified component/class name. Typically used to start a component in your own app. E.g. to start a service to download a file in background
  2. Implicit Intent: Generic. The component/app that will handle it is not specified. Eg component in another app to handle certain actions such as showing location on map. Intent filters in Apps Manifest are used to identify apps that will handle the intent. If more than one app

Intent Filters

An intent filter is an expression in an app’s manifest file that specifies the type of intents that the component would like to receive. If an intent filter is not declared, it means only explicit intents can trigger the

NOTE: Services should never be started using an implicit intent. It is a security hazard as it is not determinate which service will handle the intent. Always use an explicit event for starting services and do not specify intent filters for services.

Parts of an Intent

  1. ComponentName: Needed for explicit intents. It is an optional field as it is not specified for implicit intents. Takes the fully qualified class name or package name. Note: For a service, always speficy this field so that the systems knows exactly which component to be launched.
  2. Action: String to specify what action to be performed. Use Action constants defined by Intent class or other system classes. You can define your own action strings for intents within your app.
  3. Data: URI and/or MIME type. This field is dictated by the intent’s action. While defining intent, it is important to specify the datatype (MIME type) for the data. NOTE: to specify both URI and type use setDataAndType() instead of separate calls to setData() and setType() since each call will nullify value set by other.
  4. Category: string of optional information about what kind of components can handle this intent. eg: CATEGORY_BROWSABLE
  5. Extras: Key value pair. Additional info on how to accomplish requested action
  6. Flags : Metadata for the system to use. eg how to launch an activity.

Fields 1–4 define how the system resolves which app component it needs to start. These are the defining characteristics.

App Chooser

If multiple apps responds to same implicit intent, app chooser is launched to let user select which app handles the intent. You could allow setting of a default app.

Howver, if the user wants to use a different app each time implemetation should explicitly show a chooser dialog (user cannot set default app).

Intent Filters

Intent filters in the manifest file specify which implicit intents are accepted by the application.

Pending Intents

Grants permission to foreign application to use the intent. Its a wrapper object containing the intent.

--

--