Fragment Transaction without commit

↘锁芯ラ 提交于 2019-12-11 07:22:58

问题


I have seen the code below and unable to figure it out.

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

i am not able to understand the part when the if condition fails and commit() is called. and when if condition is true commit is not used for show transaction.

Can anyone help me understand this. because lint shows missing commit for the transaction inside the if selection.


回答1:


Use

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

call commit method when mGoalProgressFragment is not null and also remove other statement in which you are calling commit method which is not useful.show useful message in else block when mGoalProgressFragment is null.



来源:https://stackoverflow.com/questions/27791812/fragment-transaction-without-commit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!