我看过下面的代码,但无法理解。
if (mGoalProgressFragment != null) {
mCallerFramgent.getActivity().getSupportFragmentManager().beginTransaction().show(mGoalProgressFragment);
}
mCallerFramgent.getActivity().getSupportFragmentManager().beginTransaction().commit();
当 if 条件失败并调用 commit()
时,我无法理解该部分。
当条件为真时,提交不用于显示交易。
任何人都可以帮助我理解这一点。因为 lint 显示 if 选择中的事务缺少提交。
最佳答案
使用
...beginTransaction().show(mGoalProgressFragment).commit();
当 mGoalProgressFragment
不是 null
时调用 commit 方法,并且还删除其他您正在调用 commit 方法的语句,这是没有用的。在 else block 中显示有用的消息 mGoalProgressFragment
为空。
关于android - 没有提交的 fragment 事务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27791812/