相关疑难解决方法(0)

Android:清除后台堆栈

在Android中我有一些活动,比方说A,B,C.

在A中,我使用此代码打开B:

Intent intent = new Intent(this, B.class);
startActivity(intent);
Run Code Online (Sandbox Code Playgroud)

在B中,我使用此代码打开C:

Intent intent = new Intent(this, C.class);
startActivity(intent);
Run Code Online (Sandbox Code Playgroud)

当用户点击C中的按钮时,我想返回A并清除后栈(关闭B和C).因此,当用户使用后退按钮B和C将不会显示时,我一直在尝试以下内容:

Intent intent = new Intent(this, A.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
startActivity(intent);
Run Code Online (Sandbox Code Playgroud)

但是当我回到活动A时,如果我使用后退按钮,B和C仍然会出现.我怎么能避免这种情况?

stack android clear android-intent android-activity

311
推荐指数
16
解决办法
24万
查看次数

标签 统计

android ×1

android-activity ×1

android-intent ×1

clear ×1

stack ×1