skip to content

On Android, what is the difference between an explicit and an implicit intent, and how does the system resolve an implicit one?

level: juniorimportance: must knowfreq 75%

answer

  1. who picks the receiver
  2. component name vs a described job
  3. action, category and data tests
  4. startActivity adds a default category
  5. nothing matches: an exception

basics

~20 s

An explicit intent names the component to start, so Android delivers it there directly; an implicit intent describes an action, data and categories, and Android matches it against installed apps' intent filters, letting the user pick when several match.

solid answer

~40 s

An explicit intent sets a component name, for example `Intent(this, TripActivity::class.java)`, and the system starts exactly that class; apps use it for their own screens and always for services. An implicit intent leaves the component out and describes the job: an action such as `ACTION_SEND` or `ACTION_VIEW`, optional data (a URI and MIME type) and categories. The system tests it against every app's `<intent-filter>`: the action must be listed, every category in the intent must be in the filter, and the URI and type must match. Because `startActivity()` adds `CATEGORY_DEFAULT` to implicit intents, a receiving activity must declare that category. One match starts directly, several show a picker (`Intent.createChooser()` forces one each time), and none throws `ActivityNotFoundException`.

code

kotlin · 10 lines
kotlin
// Explicit: one of the app's own screens
startActivity(Intent(this, TripDetailsActivity::class.java).putExtra("tripId", tripId))

// Implicit: any installed app that can show a geo: URI
val showPickup = Intent(Intent.ACTION_VIEW, Uri.parse("geo:52.52,13.405"))
try {
    startActivity(showPickup)
} catch (e: ActivityNotFoundException) {
    Toast.makeText(this, R.string.no_map_app, Toast.LENGTH_SHORT).show()
}

go deeper

for a junior

Recall the one difference: an explicit intent names a class, an implicit one describes a job. Then list the three tests and what happens with zero, one or several matching apps.

for a middle

Explain the category test's direction and why CATEGORY_DEFAULT is needed, how the data test compares only the URI parts a filter names, and how createChooser() differs from the default-app dialog.

for a senior

Show the production edges: package visibility hiding apps from lookups on API 30 and higher, receivers targeting API 33 rejecting non-matching intents, and why filters are not access control.

for a principal

Frame which entry points the app should advertise at all: each filter is a public contract other apps can call, so the team keeps that list short and reviews it.

## Two ways to address a component An **intent** (`android.content.Intent`) is the message an app hands to the Android system to start an activity, start or bind a service, or deliver a broadcast. Whether it is explicit or implicit depends on one field, the **component name**. - An **explicit intent** sets the component, with `Intent(context, TripActivity::class.java)`, `setClassName()` or `setComponent()`. The system delivers it to that class, whatever intent filters the class declares, as long as the caller is allowed to reach it. - An **implicit intent** leaves the component empty and describes the work instead: an **action** such as `Intent.ACTION_SEND` or `Intent.ACTION_VIEW`, optional **data** (a URI, a MIME type or both) and optional **categories**. The system chooses the receiver. | | Explicit intent | Implicit intent | |---|---|---| | Carries | a component class | an action, data and categories | | Who picks the target | the sender | the system, by matching intent filters | | Typical use | your own activities and services | share text, view a location, dial a number | | For services | required | rejected by `bindService()` since Android 5.0 (API level 21) | ## How an implicit intent resolves The system compares the intent with the `<intent-filter>` elements declared in the manifests of installed apps. A component receives the intent only when the intent passes **all three tests** against one of its filters: 1. **Action test.** The intent's action must be one of the filter's `<action>` entries. A filter that lists no action matches nothing. 2. **Category test.** Every category in the intent must appear in the filter; the filter may list more. `startActivity()` treats every implicit intent as carrying `CATEGORY_DEFAULT`, so an activity that wants implicit intents must declare `android.intent.category.DEFAULT`, or nothing resolves to it. 3. **Data test.** The URI parts the filter names (`scheme`, `host`, `port`, `path`) and its MIME type must match. A filter that names only a scheme accepts every URI with that scheme. A component may declare several filters, and an intent that fails one can still pass another. ## When nothing, or several things, match - **Several matches.** The system shows a dialog so the user can pick an app, and the user may make it the default. For sharing, wrap the intent in `Intent.createChooser(sendIntent, title)`: the chooser appears every time and no default sticks. - **One match.** That app opens immediately. - **No match.** `startActivity()` throws `ActivityNotFoundException`. Catch it and disable or explain the feature. ## Package visibility and the pre-check From Android 11 (API level 30), an app that targets 30 or higher sees a **filtered** list of other apps. Lookups such as `queryIntentActivities()`, `getPackageInfo()` and `getInstalledApplications()` return only the packages visible automatically plus those the manifest asks for in a `<queries>` element, for example an `<intent>` entry for `ACTION_SEND`. The older `resolveActivity(packageManager)` pre-check goes through the same package lookup, so the simplest robust pattern is to call `startActivity()` and catch `ActivityNotFoundException`. `QUERY_ALL_PACKAGES` exists, but Google Play allows it only after reviewing the app's need. ## The receiving side - A component with an intent filter must set `android:exported` explicitly; an app that leaves it out cannot be installed on Android 12 or higher. - If the receiving app targets Android 13 (API level 33) or higher, intents from other apps reach its exported components only when they match the actions and categories of one of its filters; a sender whose intent matches none gets `ActivityNotFoundException`. - **A filter is not a lock.** Another app that knows the class name can still send an explicit intent to an exported component, so a component meant for your app alone needs `android:exported="false"`. ## Details interviewers probe - An intent with **no action** still passes the action test, as long as the filter lists at least one action. - An intent with both a URI and a MIME type passes the data test when its type matches one the filter lists and either its URI matches the filter's URI, or it is a `content:` or `file:` URI and the filter names no URI at all. - `setPackage()` on an implicit intent narrows resolution to one app's components without naming a class. - An explicit intent to another app's component still respects that component's `android:exported` value. ## In a ride-hailing app The trip details screen opens with an explicit intent to the app's own activity. "Show the pickup point" sends an implicit `ACTION_VIEW` with a `geo:` URI and lets any maps app answer, and "share my ETA" sends an implicit `ACTION_SEND` with `text/plain` through the chooser. Testing one from a terminal works the same way: `adb shell am start -a android.intent.action.VIEW -d "geo:52.52,13.405"` asks the system to resolve exactly that intent.

  • Why does an activity with an ACTION_VIEW filter never receive implicit intents from startActivity()?
    Most often the filter lacks `android.intent.category.DEFAULT`. `startActivity()` treats every implicit intent as carrying `CATEGORY_DEFAULT`, and the category test requires each of the intent's categories to be in the filter, so a filter without it never matches. Add the category, and keep `android:exported` set explicitly on the activity.
  • Your app targets API 30 and queryIntentActivities() returns an empty list although a maps app is installed. Why?
    Package visibility filtering, introduced in Android 11 (API 30), hides packages the app has not declared. Add a `<queries>` element with an `<intent>` describing the `ACTION_VIEW` and `geo` scheme you query for, and the matching maps apps become visible to the lookup. Launching with `startActivity()` does not need that visibility.
  • Is an intent filter enough to keep other apps from starting one of your activities?
    No. Filters decide which implicit intents match, but an app that knows the class name can send an explicit intent to any exported component. If only your app should start it, set `android:exported="false"` and drop the filter.

  • An explicit intent goes through intent-filter matching like any other intent
  • An activity receives implicit intents without declaring CATEGORY_DEFAULT
  • startActivity() with no matching app silently does nothing
  • An intent filter stops other apps from starting the component
  • Services should be started with implicit intents so other apps can provide them

Assumes Android 17 (API 37); package visibility filtering dates from Android 11 (API 30) and receiver-side filter enforcement from apps targeting Android 13 (API 33).