3

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!

user3689720
  • 181
  • 2
  • 11

2 Answers2

3

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

Mohammadreza Khatami
  • 1,444
  • 2
  • 13
  • 27
  • 1
    You also need to add the below to your Android.xml file to get this above code to run: ` ` – Vaz Jan 26 '23 at 21:26
0

What this is trying to do is launch another Activity within your app. The manifest is the AndroidManifest.xml. You need to declare any Activities in your app there so the OS knows about them. If you're trying to launch an Activity that isn't in your app then you need to use the Intent actions instead.

CaseyB
  • 24,780
  • 14
  • 77
  • 112