在我的活动后,我添加的第一个片段(myFragmentA)在onCreate()方法:机器人:片段中的活动:popBackStack()本片段的数量剧照相同
getSupportFragmentManager()
.beginTransaction()
.setCustomAnimations(enterAnim, exitAnim, popEnterAnim, popExitAnim)
.add(containerViewId, myFragmentA, fragmentTag)
.addToBackStack(null)
.commit();
在该第一片段当我点击一个按钮,我添加了一个新的片段(myFragmentB):
getSupportFragmentManager()
.beginTransaction()
.setCustomAnimations(enterAnim, exitAnim, popEnterAnim, popExitAnim)
.replace(containerViewId, myFragmentB, fragmentTag)
.addToBackStack(null)
.commit();
全部是伟大的这一点。
当我赶回从活动按:
@Override
public void onBackPressed() {
// >>> Just to prevent to keep the first fragment !!
if (getSupportFragmentManager().getFragments().size() > 1) {
getSupportFragmentManager().popBackStack();
}
}
返回从myFragmentB> myFragmentA按:OK
返回从myFragmentA压(只是为了验证有没有popback):失败。 myFragmentA也被删除!我想永远保持它。我不知道为什么getSupportFragmentManager()。getFragments()。size()等于2!
感谢您的帮助!
完美!非常感谢你。 – anthony