【问题标题】:Fragment Transaction without commit没有提交的分片事务
【发布时间】:2015-01-06 03:51:10
【问题描述】:

我看过下面的代码,无法弄清楚。

if (mGoalProgressFragment != null) {
  mCallerFramgent.getActivity().getSupportFragmentManager().beginTransaction().show(mGoalProgressFragment);
}
mCallerFramgent.getActivity().getSupportFragmentManager().beginTransaction().commit();

当 if 条件失败并调用 commit() 时,我无法理解该部分。 如果条件为真,则提交不用于显示事务。

谁能帮我理解这一点。因为 lint 显示 if 选择中的事务缺少提交。

【问题讨论】:

    标签: android android-fragments fragmenttransaction


    【解决方案1】:

    使用

    ...beginTransaction().show(mGoalProgressFragment).commit();
    

    mGoalProgressFragment 不是null 时调用commit 方法,并删除您正在调用commit 方法的其他语句,这没有用。当mGoalProgressFragment 为null 时,在else 块中显示有用的消息。

    【讨论】:

    • 你能告诉我 beginTransaction.commit() 究竟做了什么
    • beginTransaction 方法被调用以开始编辑操作,例如添加新片段,从当前FragmentManager 中删除片段,并调用commit 方法来调度主线程的任务以关闭当前事务。您可以获取更多信息FragmentManager
    • 非常感谢@prosper
    猜你喜欢
    • 2018-10-10
    • 1970-01-01
    • 2018-06-09
    • 2023-03-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-22
    相关资源
    最近更新 更多