Android片段如何清除以前的堆栈?

时间:2014-07-22 11:10:47

标签: android

在android活动中,我们用来清理顶级活动intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);如何实现这个片段

2 个答案:

答案 0 :(得分:2)

使用此:

private void clearBackStack() {
    FragmentManager manager = getSupportFragmentManager();
    if (manager.getBackStackEntryCount() > 0) {
        FragmentManager.BackStackEntry first = manager
                .getBackStackEntryAt(0);
        manager.popBackStack(first.getId(),
                FragmentManager.POP_BACK_STACK_INCLUSIVE);
    }
}

答案 1 :(得分:1)

FragmentManager fm = getActivity().getSupportFragmentManager();

for(int i = 0; i < fm.getBackStackEntryCount(); ++i) {   

    fm.popBackStack();
}