这是一个对我有用的简化答案,基于@Smiler。我通过Button
单击我的MainActivity
. 谢谢您的帮助!
((Button) findViewById(R.id.launchTopScreen)).setOnClickListener(v -> {
Intent intent = getPackageManager().getLaunchIntentForPackage("com.example.new.app");
intent.addFlags(Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT | Intent.FLAG_ACTIVITY_NEW_TASK);
ActivityOptions options = ActivityOptions.makeBasic().setLaunchDisplayId(1);
startActivity(intent, options.toBundle());
});
这Intent.FLAG_ACTIVITY_NEW_TASK
对于在不同的显示器上启动新应用程序非常重要。否则它将在同一个任务堆栈中启动,在同一个显示器上。
该“新应用程序”也需要android:resizeableActivity="true"
在清单中。True
是默认设置,但我指定明确并保护未来的框架更改。
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:resizeableActivity="true"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">