Skip to content Skip to sidebar Skip to footer

How To Leave The Current App And Launch An Activity Of Another App?

I have a simple Android app that needs to launch another app under certain condition, and I will need to check the condition upon the app launch. That is, either continue to launch

Solution 1:

You can launch other application using following intent

IntentLaunchIntent= getPackageManager().getLaunchIntentForPackage("com.example.abc");//pass the packagename of app you want to open
startActivity( LaunchIntent );

If you don't know the package name of application that you wanted to launch then try your hand on

PackageManager pm;
pm = getPackageManager();
//  get a list of installed apps.
packages = pm.getInstalledApplications(0);

Pass the packagename of app you want to open You can use this if A == true

else You can launch the MainActivity as

startActivity(newIntent(CurrentActivity.this,MainActivity.class));

Solution 2:

If you want to start another activity of another app without the normal IntentFilter then the easiest solutions is:

Intentintent=newIntent(Intent.ACTION_MAIN);
intent.setComponent(newComponentName("com.anotherapp.package","com.anotherapp.package.MainActivity"));
startActivity(intent);

Of course, you would need to know the package name and the Activity name you want to start

As for finishing your application call

finishAndRemoveTask();

Post a Comment for "How To Leave The Current App And Launch An Activity Of Another App?"