android - 从 Android 上不同任务堆栈中的另一个应用程序启动应用程序

标签 android android-intent

<分区>

我想从app1启动已安装的app2,简单方法如下:

Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage("com.package.app2");
startActivity(LaunchIntent);

但我还想确保 app2 和 app1 在不同的任务堆栈中:

例如。当我从 app1 启动 app2 并按下 home 键,然后我打开任务列表,我会从列表中看到 app1 和 app2,并且它们都可以成功回调。

app1 的状态应该是我从 app1 调用 app2 之前的状态。

我还应该做些什么来实现这一点?

最佳答案

尝试阅读这篇关于 launchMode 的文章

万一有人懒惰,这里是最重要的:

[...] Typically, they're launched into the task that called startActivity() (unless the Intent object contains a FLAG_ACTIVITY_NEW_TASK instruction, in which case a different task is chosen — see the taskAffinity attribute). [...]

基本上是:

Intent intent = getPackageManager().getLaunchIntentForPackage("com.package.app2");
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);

关于android - 从 Android 上不同任务堆栈中的另一个应用程序启动应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27703209/

相关文章:

android - 单击联系人图标后,将自己的应用程序图标添加到 QuickAction Dialog

Android:点击首选项按钮?

android - 在已包含的 Manifest.xml 中找不到带有 .Launcher 的启动器 Activity ?

javascript - 如何用angular2和typescript隐藏android actionbar?

Android - 启动主要设置 Activity 并不总是有效

java - 安卓开发 : Regarding the usage of shared preferences

java - ImageView 和 Intent

Android:尝试去商店时抛出异常

java - Android类之间的通信

java - 在 Android 应用程序之间共享数据的最佳实践