Skip to content

Instantly share code, notes, and snippets.

@dominicthomas
Created November 28, 2013 16:16
Show Gist options
  • Save dominicthomas/7694379 to your computer and use it in GitHub Desktop.
Save dominicthomas/7694379 to your computer and use it in GitHub Desktop.
Launch another app using an intent with package name if app has a launcher activity or using package name and class name of main activity.
// only works if app has a launcher activity
Intent launchIntent = getPackageManager().getLaunchIntentForPackage("com.example.yourapp");
startActivity(launchIntent);
// works if we know the name of the main activity, even if not a launcher
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setClassName("com.example.yourapp", "com.example.yourapp.MainActivity");
startActivity(intent);
@steadfasterX
Copy link

you made my day @dominicthomas !! thx for sharing this..

only change needed for me was using context.startActivity(intent); instead of startActivity(intent); (Android14)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment