我在一個片段得到這個代碼:非法狀態例外onActivityResult
@Override
public void onActivityResult(int requestCode, int resultCode, Intent resultData) {
if (requestCode == READ_REQUEST && resultCode == Activity.RESULT_OK) {
Uri uri;
if (resultData != null) {
uri = resultData.getData();
getChildFragmentManager().beginTransaction().add(new MyFragment(), TAG).commit();
}
}
}
然而,有碰撞有IllegalStateException異常。該活動無法在onSaveInstanceState()之後創建/恢復事務。在onActivityResult()中從另一個片段開始片段的正確方法是什麼?
的logcat:
03-17 18:55:37.372 26127 26127 E AndroidRuntime: Caused by: java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
03-17 18:55:37.372 26127 26127 E AndroidRuntime: at android.app.FragmentManagerImpl.checkStateLoss(FragmentManager.java:1434)
03-17 18:55:37.372 26127 26127 E AndroidRuntime: at android.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:1452)
03-17 18:55:37.372 26127 26127 E AndroidRuntime: at android.app.BackStackRecord.commitInternal(BackStackRecord.java:708)
03-17 18:55:37.372 26127 26127 E AndroidRuntime: at android.app.BackStackRecord.commit(BackStackRecord.java:672)
03-17 18:55:37.372 26127 26127 E AndroidRuntime: at com.xxxx.ttyy.ui.SettingsFragment.onActivityResult(Unknown Source)
03-17 18:55:37.372 26127 26127 E AndroidRuntime: at android.app.Activity.dispatchActivityResult(Activity.java:6956)
03-17 18:55:37.372 26127 26127 E AndroidRuntime: at android.app.ActivityThread.deliverResults(ActivityThread.java:4085)
03-17 18:55:37.372 26127 26127 E AndroidRuntime: ... 9 more
03-17 18:55:37.377 878 3186 W ActivityManager: Force finishing activity com.balda.intenttask/.ui.MainActivity
您可以添加logcat的,好嗎? –
而你嘗試使用'的BeginTransaction()。replace'呢? –
@ cricket_007我不想更換片段 – greywolf82