我有一个简单的 Android 应用程序,需要在特定条件下启动另一个应用程序,我需要在应用程序启动时检查条件。也就是说,要么继续启动我的应用程序,要么启动另一个应用程序:
if (A == true) {
launch another activity of another app
leave the current app without creating the main activity
} else {
launch the main activity of the current app
}
谁能让我知道如何处理 A == true 案例?我能够启动另一个应用程序的活动,但我什至无法在不打开主要活动的情况下离开当前应用程序。
任何帮助将不胜感激!
您可以使用以下意图启动其他应用程序
Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage("com.example.abc");//pass the packagename of app you want to open
startActivity( LaunchIntent );
如果您不知道要启动的应用程序的包名称,请尝试
PackageManager pm;
pm = getPackageManager();
// get a list of installed apps.
packages = pm.getInstalledApplications(0);
传递要打开的应用程序的包名 如果 A == true,则可以使用它
否则您可以将 MainActivity 启动为
startActivity(new Intent(CurrentActivity.this,MainActivity.class));
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句