如何清除碎片堆和栈的活动按钮上点击 [英] how to clear the fragment stack and activity stack on a button click
问题描述
有类似的问题,但没有一个是解决我的问题。 我的应用程序流程如下:
There are similar questions, but none of the are solving my issue. My app flow is following:
活动主场活动启动B(由它来完成设置工作) 在b活动举办三个屏幕的片段... 片段1 - > fragment2->片段3。
Activity home starts Activity B(which does the setup work) In activity B hosts three screens as fragments... Fragment1 -> fragment2-> fragment 3.
这是我做的碎片。我不使用replace.just添加。
This is how I make fragments. I am not using replace.just adding it.
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
Fragment fragment = null;
if (getFragType().equals("simple")) {
fragment = new SimpleFragment().newInstance();
}
if (getFragType.equals("inter")) {
if (getFragType.getComponent().equals("con"))
fragment = new SetupConFragment().newInstance();
else if (getFragType.getComponent().equals("ben"))
fragment = new SetupBenageFragment().newInstance();
}
fragmentTransaction.add(R.id.fragment_container, fragment);
fragmentTransaction.commit();
}
Fragment3有一个完成的按钮。因此,一旦所有的3个步骤,从片段3日上午完成推出新的活动℃。
Fragment3 has a done button. So once all the 3 steps are done from fragment 3 am launching a new activity C.
的问题是: - 从活动C,如果用户presses后退按钮,它diplays片段2,然后分段1.理想的情况下,一旦用户在活动C,回preSS应该只是退出屏幕 我已经使用的意图的标志的所有组合,但它是没有帮助
The issue is:-- From the activity C , if the user presses the back button, it diplays fragment 2, then fragment 1. Ideally once the user is in Activity C, back press should just exit the screen I have used all combinations of the intent flags, but it is not helping.
这是我按一下按钮。
Intent launch = new Intent(mContext, MainActivity.class);
launch.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
launch.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
launch.putExtra("Exit me", true);
mContext.startActivity(launch);
((ConfigureActivity)mContext).finish();
任何帮助将AP preciated。
Any help will be appreciated.
推荐答案
您可以做到这一点的方式:
You can do this way:
清除碎片堆
getSupportFragmentManager().popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);
清除活动堆栈
Intent intent = new Intent(Your_Current_Activity.this, Your_Destination_Activity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK |Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
希望这会帮助你。
Hope this will help you.
这篇关于如何清除碎片堆和栈的活动按钮上点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!