如何清除堆栈碎片

时间:2019-01-29 12:40:47

标签: android kotlin

我在清理堆栈时遇到问题。 此方法显示了我的片段:

private fun showFragment(fragment: Fragment, titleTag: String) {

    supportFragmentManager.beginTransaction()
        .replace(R.id.container, fragment, titleTag)
        .addToBackStack(titleTag)
        .commit()

    if (drawer_layout.isDrawerOpen(GravityCompat.END)) {
        drawer_layout.closeDrawer(GravityCompat.END)
    }
}

我不知道如何清除堆栈。

1 个答案:

答案 0 :(得分:3)

FragmentManager manager = getFragmentManager();
FragmentManager.BackStackEntry first = manager.getBackStackEntryAt(0);
manager.popBackStack(first.getId(), FragmentManager.POP_BACK_STACK_INCLUSIVE);