如何关闭 运行 应用的所有活动并在点击时重新启动一个新的应用

How to close all of the activities of running app and Re-launch a fresh app on click

我有多个屏幕的应用程序 我的应用程序从 splash(Launcher)->Home Screen->Child Screen 启动。 当用户点击 URL 应用程序时直接跳转到子屏幕(应用程序需要)。 但是当用户点击 URL 时,会启动一个我不想要的新应用程序实例。我想关闭现有的应用程序并使用 Child Screen 启动新的应用程序。每个 activity 都有 android:launchMode="singleTop"

为了启动新的应用程序,我找到了这个解决方案并且它对我来说工作正常

Intent intent = new Intent(Firstctivity.this, SecondActivity.class);
intent .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent );
finish();

它将关闭正在进行的 Task 并为我创建一个新的..:)