v4包 fragment 报错:java.lang.IllegalStateException: Failure saving state:

12-05 14:38:19.048: E/FragmentManager(20791): Failure saving state: active CasePlayBackFragment{1a71c06c} has cleared index: -1
12-05 14:38:19.048: E/FragmentManager(20791): Activity state:
12-05 14:38:19.119: E/AndroidRuntime(20791): FATAL EXCEPTION: main
12-05 14:38:19.119: E/AndroidRuntime(20791): Process: com.smartspyeye.livevideo, PID: 20791
12-05 14:38:19.119: E/AndroidRuntime(20791): java.lang.IllegalStateException: Failure saving state: active CasePlayBackFragment{1a71c06c} has cleared index: -1
12-05 14:38:19.119: E/AndroidRuntime(20791):  at android.support.v4.app.FragmentManagerImpl.saveAllState(FragmentManager.java:1773)
12-05 14:38:19.119: E/AndroidRuntime(20791):  at android.support.v4.app.Fragment.performSaveInstanceState(Fragment.java:2111)
12-05 14:38:19.119: E/AndroidRuntime(20791):  at android.support.v4.app.FragmentManagerImpl.saveFragmentBasicState(FragmentManager.java:1716)
12-05 14:38:19.119: E/AndroidRuntime(20791):  at android.support.v4.app.FragmentManagerImpl.saveAllState(FragmentManager.java:1784)
12-05 14:38:19.119: E/AndroidRuntime(20791):  at android.support.v4.app.FragmentController.saveAllState(FragmentController.java:125)
12-05 14:38:19.119: E/AndroidRuntime(20791):  at android.support.v4.app.FragmentActivity.onSaveInstanceState(FragmentActivity.java:487)
12-05 14:38:19.119: E/AndroidRuntime(20791):  at android.app.Activity.performSaveInstanceState(Activity.java:1309)
12-05 14:38:19.119: E/AndroidRuntime(20791):  at android.app.Instrumentation.callActivityOnSaveInstanceState(Instrumentation.java:1299)
12-05 14:38:19.119: E/AndroidRuntime(20791):  at android.app.ActivityThread.callCallActivityOnSaveInstanceState(ActivityThread.java:4251)
12-05 14:38:19.119: E/AndroidRuntime(20791):  at android.app.ActivityThread.performStopActivityInner(ActivityThread.java:3626)
12-05 14:38:19.119: E/AndroidRuntime(20791):  at android.app.ActivityThread.handleStopActivity(ActivityThread.java:3690)
12-05 14:38:19.119: E/AndroidRuntime(20791):  at android.app.ActivityThread.access$1100(ActivityThread.java:178)
12-05 14:38:19.119: E/AndroidRuntime(20791):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1494)
12-05 14:38:19.119: E/AndroidRuntime(20791):  at android.os.Handler.dispatchMessage(Handler.java:111)
12-05 14:38:19.119: E/AndroidRuntime(20791):  at android.os.Looper.loop(Looper.java:194)
12-05 14:38:19.119: E/AndroidRuntime(20791):  at android.app.ActivityThread.main(ActivityThread.java:5637)
12-05 14:38:19.119: E/AndroidRuntime(20791):  at java.lang.reflect.Method.invoke(Native Method)
12-05 14:38:19.119: E/AndroidRuntime(20791):  at java.lang.reflect.Method.invoke(Method.java:372)
12-05 14:38:19.119: E/AndroidRuntime(20791):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:959)
12-05 14:38:19.119: E/AndroidRuntime(20791):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:754)



解决方法 :在替换fragment到时候,增加两句:

beginTransaction.addToBackStack(fragmentTag);
beginTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);


完整替换使用如下的方法:

FragmentManager fragmentManager = getChildFragmentManager();
FragmentTransaction beginTransaction = fragmentManager.beginTransaction();
beginTransaction.replace(R.id.fl_frame, casePlayBackFragment,fragmentTag);
beginTransaction.addToBackStack(fragmentTag);
beginTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
beginTransaction.commit();

你可能感兴趣的:(Android)