关闭当前片段并打开前一个片段

Close the currrent fragment and open the previous one

假设我的主 activity 中有一个 frameLayout,还有两个片段, 所以现在正在显示第一个片段,我用 secondFragment 替换它并将第一个片段添加到后退堆栈,现在第二个片段满足了一些条件所以我想关闭第二个片段并打开我们离开的第一个片段(基本上从返回堆栈)而不按返回按钮。我该如何实现?

您可以编写此代码以从后台堆栈中删除当前片段:

getActivity().getSupportFragmentManager().popBackStack();