致命异常:java.lang.RuntimeException:无法恢复 activity

Fatal Exception: java.lang.RuntimeException: Unable to resume activity

以下是我的日志转发

Fatal Exception: java.lang.RuntimeException: Unable to resume activity {com.maruticourier.android/com.marutideliver.activity.MainActivity}: java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3069) at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3098) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1350) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:146) at android.app.ActivityThread.main(ActivityThread.java:5653) at java.lang.reflect.Method.invokeNative(Method.java) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1291) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107) at dalvik.system.NativeStart.main(NativeStart.java) Caused by java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState at android.support.v4.app.FragmentManagerImpl.checkStateLoss(FragmentManager.java:1365) at android.support.v4.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:1383) at android.support.v4.app.BackStackRecord.commitInternal(BackStackRecord.java:636) at android.support.v4.app.BackStackRecord.commit(BackStackRecord.java:615) at com.marutideliver.activity.MainActivity.selectItem(MainActivity.java:485) at com.marutideliver.activity.MainActivity.onResume(MainActivity.java:810) at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1198) at android.app.Activity.performResume(Activity.java:5620) at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3059) at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3098) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1350) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:146) at android.app.ActivityThread.main(ActivityThread.java:5653) at java.lang.reflect.Method.invokeNative(Method.java) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1291) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107) at dalvik.system.NativeStart.main(NativeStart.java)

这是支持中的错误package.To避免这种情况,您可以在片段事务期间使用以下内容。

transaction.commitAllowingStateLoss();

如果你 google 它,你会找到很多关于 it.For 的很好的答案,更多参考和替代方法请参阅此 SO post and this SO post。希望它有所帮助。

您可能有一个 non-static 子类(我猜它是一个片段),您的 activity 每次恢复时都无法实例化。如果你有这样的子类,只需将其设为静态即可。

可能是因为多次使用add()方法和public方法如

 public void beginTransaction(ID id, Bundle bundle)

避免使用

fragmentmanager.begintransaction().add

每次,

也用这个来替换

fragmentmanager.begintransaction().replace(r.id.frame_container, fragment).commit()

可能是因为没有覆盖 onResume() 方法,您必须覆盖并恢复您的 save-instance 之前的存储