android - 没有提交的 fragment 事务

标签 android android-fragments fragmenttransaction

我看过下面的代码,但无法理解。

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/

相关文章:

java - 为不同的本地化定制日期/时间显示格式的好方法是什么

java - Android dataBinding - TextView 根据 boolean 值不可见

android - 使用导航组件将 View 模型限定为多个 fragment (不是 Activity )

android - FragmentTransaction 不显示替换的 fragment

android - 从 Play 商店下载 apk 后,谷歌地图无法在 Android 中运行

java - 如何在评估子项目之前执行 Gradle 任务

android - fragment 事务加载空 View 但 fragment 在旋转设备后显示

android - 如何在MainActivity中保存在不同事务中提交的两个 fragment 的InstanceState?

android - Android Kotlin协程:使用Global范围是否是反模式?

java - 从 ArrayList 适配器设置可见 View ,该 View 驻留在与 Activity 不同的文件中