简体   繁体   English

从堆栈中清除启动器活动

[英]Clearing the Launcher Activity from the stack

In my app, I have activity A (Launcher/Main Activity) ,B,C. 在我的应用中,我有活动A(发起人/主要活动),B,C。 A launches B or C depending on if the user is authenticated. A根据用户是否通过身份验证启动B或C。

Now how do I remove A such that when the back button is pressed it just exits the app, not to A. Setting the flag FLAG_ACTIVITY_CLEAR_TOP doesn't seem to work. 现在,我如何删除A,以便在按下后退按钮时仅退出应用程序,而不是退出A。设置标志FLAG_ACTIVITY_CLEAR_TOP似乎无效。

@Override
public void onBackPressed{
    super.onBackPressed();
    finish(); // finish activity B or C

    //also finish activity A
}

I think you need to set 我认为你需要设定

android:noHistory="true"

on A. You might also need to launch B/C with these Flags: 在A上。您可能还需要使用以下标志启动B / C:

intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);    

Finally, you can finish all activities under the current one in the task stack with the same affinity by calling: 最后,您可以通过调用以下命令以相同的相似性完成任务堆栈中当前活动下的所有活动:

finishAffinity()

For further information: Android: Clear the back stack 有关更多信息: Android:清除后堆栈

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM