2016-06-29 34 views
0
的onSaveInstanceState後

我展示一個按鈕onClick事件裏面DialogFragment像下面執行此操作:致命異常:java.lang.IllegalStateException:不能

public void onButtonClick() { 
    myDialogFragment.show(getSupportFragmentManager(), "dialog"); 
} 

爲什麼它會導致IllegalStateException異常,可能的onSaveInstanceState它稱爲後? 這裏是日誌:

Fatal Exception: java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState 
    at android.support.v4.app.FragmentManagerImpl.checkStateLoss(FragmentManager.java:1377) 
    at android.support.v4.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:1395) 
    at android.support.v4.app.BackStackRecord.commitInternal(BackStackRecord.java:637) 
    at android.support.v4.app.BackStackRecord.commit(BackStackRecord.java:616) 
    at android.support.v4.app.DialogFragment.show(DialogFragment.java:139) 
    at com.a.b.AFragment.editSex(AFragment.java:226) 
    at com.a.b.AFragment.access$200(AFragment.java:46) 
    at com.a.b.AFragment$3.onButtonClick(AFragment.java:134) 
+0

看看這個http://stackoverflow.com/questions/22713002/java-lang-illegalstateexception-can-not-perform-this-action-after-onsaveinstanc –

+0

發佈一些代碼的logcat – Chandrakanth

+0

請仔細閱讀這個http://stackoverflow.com/help/how-to-ask – Chandrakanth

回答

0

裏面你的表演方法調用此

fragmentTransaction.commitAllowingStateLoss() 

添加片段

fragmentTransaction.add(); 

僅供參考後

像犯,但允許承諾在執行後執行活動的狀態被保存。這很危險,因爲如果活動需要稍後從其狀態恢復,那麼提交可能會丟失,所以這應該僅用於UI狀態在用戶意外更改的情況。

+0

commitAllowingStateLoss不是一個好的選擇。 –

相關問題