当我从片段中打开活动时会发生此错误。加载该活动后,应用程序崩溃。
Intent intent = new Intent(getActivity(), TestActivity.class);
getParentFragment().startActivityForResult(intent, 100);
On Go through through stack overflow发现在尝试片段事务时会发生这种情况,我们没有引用正确的片段实例。但我没有在该活动中完成任何片段交易。何时会发生此错误以及如何处理?
错误日志:
11-29 10:11:43.786:E / AndroidRuntime(18088): java.lang.IllegalStateException:失败保存状态:活动 TestFragment {1fa01248}已清除索引:-1 11-29 10:11:43.786: E / AndroidRuntime(18088):at android.support.v4.app.FragmentManagerImpl.saveAllState(FragmentManager.java:1767) 11-29 10:11:43.786:E / AndroidRuntime(18088):at android.support.v4.app.FragmentActivity.onSaveInstanceState(FragmentActivity.java:527) 11-29 10:11:43.786:E / AndroidRuntime(18088):at android.app.Activity.performSaveInstanceState(Activity.java:1298) 11-29 10:11:43.786:E / AndroidRuntime(18088):at android.app.Instrumentation.callActivityOnSaveInstanceState(Instrumentation.java:1288) 11-29 10:11:43.786:E / AndroidRuntime(18088):at android.app.ActivityThread.callCallActivityOnSaveInstanceState(ActivityThread.java:3958) 11-29 10:11:43.786:E / AndroidRuntime(18088):at android.app.ActivityThread.performStopActivityInner(ActivityThread.java:3369) 11-29 10:11:43.786:E / AndroidRuntime(18088):at android.app.ActivityThread.handleStopActivity(ActivityThread.java:3425) 11-29 10:11:43.786:E / AndroidRuntime(18088):at android.app.ActivityThread.access $ 1100(ActivityThread.java:151)11-29 10:11:43.786:E / AndroidRuntime(18088):at android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1327) 11-29 10:11:43.786:E / AndroidRuntime(18088):at android.os.Handler.dispatchMessage(Handler.java:102)11-29 10:11:43.786:E / AndroidRuntime(18088):at android.os.Looper.loop(Looper.java:135)11-29 10:11:43.786: E / AndroidRuntime(18088):at android.app.ActivityThread.main(ActivityThread.java:5254)11-29 10:11:43.786:E / AndroidRuntime(18088):at java.lang.reflect.Method.invoke(Native Method)11-29 10:11:43.786: E / AndroidRuntime(18088):at java.lang.reflect.Method.invoke(Method.java:372)11-29 10:11:43.786: E / AndroidRuntime(18088):at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:903) 11-29 10:11:43.786:E / AndroidRuntime(18088):at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)