Question

How to Launch an Activity from Another App in Android Using Intents

kotlinjavaandroidandroid-intent

Question

I want to launch an installed application package from my Android app. I assume this is possible using Android intents, but I have not found a clear way to do it. How can I open another installed app, or one of its activities, from my application? Is there official guidance or a standard approach for this?

Short Answer

By the end of this page, you will understand how Android apps can start activities in other apps using Intent objects. You will learn the difference between launching an app normally versus targeting a specific activity, how to use PackageManager, how to check whether the target app exists, and how to avoid common errors such as ActivityNotFoundException.

Concept

In Android, apps do not usually call each other directly. Instead, they communicate through a messaging system built around intents.

An Intent describes an action to perform, such as:

  • opening a screen
  • sharing data
  • viewing a web page
  • launching another app

When you want to start an activity from another application, you usually do one of these:

  • Launch the app's main entry activity using its package name
  • Launch a specific exported activity using an explicit intent
  • Ask Android to find a matching activity using an implicit intent

This matters because Android apps are sandboxed. One app cannot freely access another app's internal classes or screens unless that screen is exposed in the target app's manifest.

Two common ways to launch another app

1. Launch the app normally

If you only want to open another installed app, the standard approach is:

  • get the launch intent for the package
  • check if it exists
  • call startActivity()

This is the safest and most common method.

2. Launch a specific activity

If you know the exact package name and activity class name, you can build an explicit intent with setClassName() or ComponentName.

This only works if:

  • the activity exists
  • the activity is exported or otherwise accessible
  • your app has any required permissions

Why this concept matters

This pattern is used in many Android apps for:

  • opening map apps
  • launching payment apps
  • redirecting users to companion apps
  • deep-linking into settings or external tools
  • integrating with apps that expose public activities

Because not every device has the same installed apps, your code should always handle the case where the target app is missing or cannot be opened.

Mental Model

Think of an Android Intent like a delivery note.

  • The package name is the building address.
  • The activity name is the specific room inside the building.
  • Android is the courier that decides where the message goes.

If you only provide the building address, Android can open the main entrance of that app. If you provide both the building and the room, Android tries to open that exact screen. If the building does not exist, or the room is private, the delivery fails.

So launching another app is not about calling its code directly. It is about sending Android a properly addressed request.

Take Quiz

Syntax and Examples

Launch another installed app by package name

This is the most common approach.

Intent launchIntent = getPackageManager().getLaunchIntentForPackage("com.example.otherapp");
if (launchIntent != null) {
    startActivity(launchIntent);
} else {
    // App is not installed
}

How it works

  • getPackageManager() gives access to information about installed apps
  • getLaunchIntentForPackage(...) asks Android for the app's main launch activity
  • if it returns null, the app is not installed or has no launchable activity

Launch a specific activity in another app

Intent intent = new Intent();
intent.setClassName(
    "com.example.otherapp",
    "com.example.otherapp.MainActivity"
);
startActivity(intent);

Important

This works only if that activity is accessible from your app.

Safer version with error handling

Intent intent = new Intent();
intent.setClassName(
    "com.example.otherapp",
    "com.example.otherapp.MainActivity"
);

try {
    startActivity(intent);
} catch (ActivityNotFoundException e) {
    // Activity does not exist or cannot be opened
}

Example: open another app if installed

String packageName = "com.spotify.music";
PackageManager pm = getPackageManager();
Intent intent = pm.getLaunchIntentForPackage(packageName);

if (intent != null) {
    startActivity(intent);
} else {
    Toast.makeText(this, "App not installed", Toast.LENGTH_SHORT).show();
}

This example tries to open Spotify. If it is not installed, the user sees a message instead of the app crashing.

Step by Step Execution

Consider this example:

String packageName = "com.example.otherapp";
Intent launchIntent = getPackageManager().getLaunchIntentForPackage(packageName);

if (launchIntent != null) {
    startActivity(launchIntent);
}

Step by step

1. Store the target package name

String packageName = "com.example.otherapp";

This is the unique identifier of the installed app you want to open.

2. Ask Android for that app's launch intent

Intent launchIntent = getPackageManager().getLaunchIntentForPackage(packageName);

Android looks for the main launcher activity of that package.

Possible results:

  • returns an Intent if the app is installed and launchable
  • returns null if the package is missing or has no launcher activity

3. Check whether the intent exists

if (launchIntent != null) {

This prevents a crash.

4. Start the target activity

startActivity(launchIntent);

Your app asks Android to open the other app's main screen.

What happens if the app is not installed?

Then launchIntent is null, so the if block is skipped.

A more complete version would handle that case:

String packageName = "com.example.otherapp";
Intent launchIntent = getPackageManager().getLaunchIntentForPackage(packageName);

if (launchIntent != null) {
    startActivity(launchIntent);
} else {
    Toast.makeText(this, "Target app is not installed", Toast.LENGTH_SHORT).show();
}

Real World Use Cases

Common practical uses

Open a companion app

A wearable app may open its paired phone app.

Launch navigation or map apps

Your app may send the user to Google Maps or another navigation app.

Start a payment or wallet app

A shopping app may redirect the user to an installed payment provider.

Open messaging or email apps

You may launch another app to continue an action there.

Enterprise and kiosk workflows

A company device may move users between approved internal apps.

Examples in real apps

  • A banking app opening a trusted authentication app
  • A store app opening a delivery partner app
  • A file app opening a PDF viewer
  • A launcher app opening installed apps by package name
  • A support app opening device settings or system screens
Take Quiz

Real Codebase Usage

In real Android projects, developers usually do more than just call startActivity().

Common patterns

Guard clause for missing app

Intent intent = getPackageManager().getLaunchIntentForPackage("com.example.otherapp");
if (intent == null) {
    return;
}
startActivity(intent);

This is a simple guard clause: exit early if the app cannot be launched.

Show a fallback message or store link

Intent intent = getPackageManager().getLaunchIntentForPackage("com.example.otherapp");
if (intent != null) {
    startActivity(intent);
} else {
    Toast.makeText(this, "Please install the app first", Toast.LENGTH_LONG).show();
}

In production, many apps also redirect users to Google Play.

Centralize app-launch logic

Large projects often keep this logic in a helper method:

public void openApp(String packageName) {
    Intent intent = getPackageManager().getLaunchIntentForPackage(packageName);
    if (intent != null) {
        startActivity(intent);
    }
}

This avoids repeated code.

Handle errors when targeting specific activities

try {
    Intent intent = new Intent();
    intent.setClassName("com.example.otherapp", "com.example.otherapp.MainActivity");
    startActivity(intent);
} catch (ActivityNotFoundException e) {
    Log.e("AppLaunch", "Target activity not found", e);
}

This is common when integrating with external apps whose internal screens may change.

Validate assumptions

Developers do not assume that:

  • the app is installed
  • the activity name stays the same forever
  • the activity is exported
  • the target app behaves the same on every device

Common Mistakes

1. Starting an app without checking for null

Broken code:

Intent intent = getPackageManager().getLaunchIntentForPackage("com.example.otherapp");
startActivity(intent);

Problem:

  • if the app is not installed, intent is null
  • this can cause a crash

Fix:

Intent intent = getPackageManager().getLaunchIntentForPackage("com.example.otherapp");
if (intent != null) {
    startActivity(intent);
}

2. Confusing package name with activity name

Broken code:

intent.setClassName("com.example.otherapp.MainActivity", "com.example.otherapp");

Problem:

  • the first value should be the package
  • the second value should be the full activity class name

Fix:

intent.setClassName("com.example.otherapp", "com.example.otherapp.MainActivity");

3. Trying to open a private activity

Not every activity in another app is available to your app.

Problem:

  • the activity may not be exported
  • Android may block access

Avoid it by:

  • preferring the launch intent when possible
  • using documented public entry points from the target app

4. Forgetting that external apps may not be installed

Your app must always handle missing packages.

Good practice:

  • show a message
  • disable the button if the app is unavailable
  • offer installation guidance

5. Assuming every app has a launcher activity

Some packages are libraries, services, or background-only apps.

So getLaunchIntentForPackage() can return null even if the package exists.

6. Ignoring Android visibility rules on newer versions

On newer Android versions, package visibility can affect whether your app can query installed packages.

If needed, declare package visibility in your manifest using the appropriate <queries> entries. This is especially relevant when checking for other installed apps.

Comparisons

ApproachWhat it doesBest forLimitations
getLaunchIntentForPackage()Opens the app's main launch activityOpening another app normallyRequires a launchable activity
setClassName() / explicit intentOpens a specific activity in another appKnown public activity entry pointsFails if activity is private, missing, or renamed
Implicit intentLets Android find a matching app/activityStandard actions like view, share, dialLess control over exact target

Explicit intent vs implicit intent

TypeYou specifyExample
Explicit intentExact package/classOpen com.example.otherapp.MainActivity
Implicit intentAction and optional dataOpen a URL in any browser

When to use which

  • Use getLaunchIntentForPackage() when you want to open another app like the user tapped its icon.
  • Use an explicit intent when the other app documents a public activity to open.
  • Use an implicit intent when the task is general, such as viewing a web page or sharing content.
Take Quiz

Cheat Sheet

Quick reference

Launch another app

Intent intent = getPackageManager().getLaunchIntentForPackage("com.example.otherapp");
if (intent != null) {
    startActivity(intent);
}

Launch a specific activity

Intent intent = new Intent();
intent.setClassName("com.example.otherapp", "com.example.otherapp.MainActivity");
startActivity(intent);

Safe version with try/catch

try {
    Intent intent = new Intent();
    intent.setClassName("com.example.otherapp", "com.example.otherapp.MainActivity");
    startActivity(intent);
} catch (ActivityNotFoundException e) {
    // handle error
}

Rules to remember

  • Use PackageManager to find launch intents
  • Check for null before calling startActivity()
  • A package name is not the same as an activity class name
  • You can only open activities that are available to your app
  • Prefer documented public entry points
  • Handle the case where the app is not installed

Common classes

  • Intent
  • PackageManager
  • ComponentName
  • ActivityNotFoundException

Edge cases

  • target app not installed
  • target package has no launcher activity
  • specific activity is not exported
  • package visibility restrictions on newer Android versions

FAQ

How do I open another installed app in Android?

Use getPackageManager().getLaunchIntentForPackage(packageName) and call startActivity() if the result is not null.

Can I open a specific activity from another app?

Yes, with an explicit intent such as setClassName(), but only if that activity is accessible and exported.

What happens if the target app is not installed?

getLaunchIntentForPackage() usually returns null, so you should check before starting the activity.

Why does ActivityNotFoundException happen?

It happens when Android cannot find the activity you requested, or your app is not allowed to open it.

Is using intents the standard way to launch another app?

Yes. Intents are the standard Android mechanism for requesting actions across apps.

Do I need permissions to launch another app?

Usually not for a normal launch intent, but some specific activities or integrations may require permissions.

Can every activity in another app be launched externally?

No. Only activities exposed by that app and allowed by Android's security rules can be launched.

Where can I find official Android information?

The official Android documentation for Intent, PackageManager, and activity launching is the right place to start.

Take Quiz

Mini Project

Description

Build a small Android screen with a button that tries to open another installed app by package name. If the app is unavailable, show a message instead. This demonstrates the safest beginner-friendly pattern for launching external apps.

Goal

Create an Android activity that opens another app if it is installed and handles the missing-app case without crashing.

Requirements

  • Create a button in an Android activity
  • When the button is tapped, try to open an app using its package name
  • Check whether a launch intent exists before calling startActivity()
  • Show a toast message if the app is not installed
Take Quiz

Keep learning

Related questions

View more