我想从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);