如何清除碎片堆和栈的活动按钮上点击碎片、按钮

由网友(自找的痛ぃ何必喊疼)分享简介:有类似的问题,但没有一个是解决我的问题。我的应用程序流程如下:There are similar questions, but none of the are solving my issue.My app flow is following:活动主场活动启动B(由它来完成设置工作)在b活动举办三个屏幕的片段...

有类似的问题,但没有一个是解决我的问题。 我的应用程序流程如下:

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.

阅读全文

相关推荐

最新文章