如何离开当前应用程序并启动另一个应用程序的活动? [英] How to leave the current app and launch an activity of another app?

查看:75
本文介绍了如何离开当前应用程序并启动另一个应用程序的活动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的Android应用程序,需要在特定条件下启动另一个应用程序,并且在应用程序启动时需要检查条件.也就是说,要么继续启动我的应用程序,要么只是启动另一个应用程序:

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 my app or just launch another app:

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 ==真实情况吗?我能够启动另一个应用程序的活动,但是即使不打开主活动也无法离开当前应用程序.

Could anyone please let me know how to deal with A == true case? I am able to launch another app's activity but I have trouble leaving the current app without even opening the main activity.

任何帮助将不胜感激!

推荐答案

您可以使用以下意图启动其他应用程序

You can launch other application using following intent

Intent LaunchIntent = 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);

传递您要打开的应用程序的程序包名称如果A == true,则可以使用此

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

否则,您可以启动MainActivity为

else You can launch the MainActivity as

startActivity(new Intent(CurrentActivity.this,MainActivity.class));

这篇关于如何离开当前应用程序并启动另一个应用程序的活动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆