我在清理堆栈时遇到问题。 此方法显示了我的片段:
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)
}
}
我不知道如何清除堆栈。
答案 0 :(得分:3)
FragmentManager manager = getFragmentManager();
FragmentManager.BackStackEntry first = manager.getBackStackEntryAt(0);
manager.popBackStack(first.getId(), FragmentManager.POP_BACK_STACK_INCLUSIVE);