Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Launch Another App From My App Android [duplicate]

I'm simply trying to launch one of my apps from within another app. I have this code:

Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setComponent(new ComponentName("com.my.app","com.my.app.Main"));
startActivity(intent);

But it keeps giving me this error:

Unable to find explicit activity class {com.my.app/com.my.app.Main}; have you declared this activity in your AndroidManifest.xml?

Which manifest is it referring to? The second app that I'm trying to launch, or the app from which I'm trying to launch it? Also, what am I supposed to be declaring exactly?

If you need more information, please let me know. It's probably something simple but I've looked through all the related questions / answers on SO and none of the solutions worked for me.

Thanks!

like image 888
user3689720 Avatar asked Sep 07 '25 12:09

user3689720


1 Answers

Use this, the package name can be used to launch the application.

Intent launchIntent = getPackageManager().getLaunchIntentForPackage("com.package.address");
if (launchIntent != null) { 
    startActivity(launchIntent);//null pointer check in case package name was not found
}

I hope this helps you

like image 192
Mohammadreza Khatami Avatar answered Sep 10 '25 01:09

Mohammadreza Khatami