问题
Following is My Log Repost
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)
回答1:
It's may be because of not overwrite onResume() method you must overwite and restore your save-instance that previous store
回答2:
This is a bug in support package.To avoid this you can use following during fragment transaction.
transaction.commitAllowingStateLoss();
If you google it you'll find many good answers to it.For more reference and alternate methods see this SO post and this SO post.Hope it helps.
回答3:
You probably have a non-static subclass (I'm guessing it's a fragment) that your activity fails to instantiate every time it is resumed. In case you have such subclass, just make it static.
回答4:
It's may be because of using add()
method many times with public method like
public void beginTransaction(ID id, Bundle bundle)
Avoid using
fragmentmanager.begintransaction().add
each time,
Use this too for replacing
fragmentmanager.begintransaction().replace(r.id.frame_container, fragment).commit()
来源:https://stackoverflow.com/questions/35054413/fatal-exception-java-lang-runtimeexception-unable-to-resume-activity