2015-01-06 147 views
1

我已經看到下面的代碼,無法弄清楚。片段交易沒有提交

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

我不能夠當如果條件不滿足,並commit()被稱爲理解的部分。 當條件爲真時,提交不用於顯示事務。

任何人都可以幫助我理解這一點。因爲lint在if選擇內顯示缺少對事務的提交。

回答

1

使用

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

調用commit方法時mGoalProgressFragmentnull並刪除其他的語句中,你是在調用commit未在其他塊useful.show有用的消息時mGoalProgressFragment爲null方法。

+0

你能告訴我beginTransaction.commit()實際上做了什麼 – Chaitanya

+0

調用'beginTransaction'方法來啓動編輯操作,如添加新的分層,從當前的'FragmentManager'中移除分段,調用'commit'方法來調度任務主線程關閉當前事務。你可以得到更多的信息[FragmentManager](http://developer.android.com/reference/android/support/v4/app/FragmentManager.html#beginTransaction%28%29) –

+0

非常感謝@prosper – Chaitanya