how can I launch a specific activity from a different app without leaving the app

74 views Asked by At

I want to start an app which has multiple launchers/shortcuts, I have tried packageManager.getLaunchIntentForPackage() but it starts the default main activity of that app that too outside my app.

I haven't worked a lot with core android concepts. is there a way to do this?

example of one such apps

1

There are 1 answers

3
Ivan Karlo Rukavina On

To do that you need to use Intent https://developer.android.com/reference/android/content/Intent

This is example how you could start new activity

Intent intent = new Intent();
intent.setComponent(new ComponentName("com.example.yourapp", "com.example.yourapp.SecondActivity"));
startActivity(intent);

Technically, when you launch an activity from another app, you're not "leaving" your app in the sense that your app is being shut down, the new activity is simply placed on top of the activity stack.