片段活动异常:在名为

时间:2016-08-10 07:28:47

标签: android android-fragments onbackpressed

我从google play获得了以下崩溃转储。

Fatal Exception: java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
   at android.support.v4.app.FragmentManagerImpl.checkStateLoss(FragmentManager.java:1527)
   at android.support.v4.app.FragmentManagerImpl.popBackStackImmediate(FragmentManager.java:599)
   at android.support.v4.app.FragmentActivity.onBackPressed(FragmentActivity.java:178)
   at com.myapp.activities.ActivityManageContacts.onBackPressed(ActivityManageContacts.java:265)
   at android.app.Activity.onKeyUp(Activity.java:2465)
   at android.view.KeyEvent.dispatch(KeyEvent.java:2646)
   at android.app.Activity.dispatchKeyEvent(Activity.java:2716)
   at android.support.v7.app.AppCompatActivity.dispatchKeyEvent(AppCompatActivity.java:533)
   at android.support.v7.view.WindowCallbackWrapper.dispatchKeyEvent(WindowCallbackWrapper.java:53)
   at android.support.v7.app.AppCompatDelegateImplBase$AppCompatWindowCallbackBase.dispatchKeyEvent(AppCompatDelegateImplBase.java:254)
   at android.support.v7.view.WindowCallbackWrapper.dispatchKeyEvent(WindowCallbackWrapper.java:53)
   at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:2276)
   at android.view.ViewRootImpl$ViewPostImeInputStage.processKeyEvent(ViewRootImpl.java:4038)
   at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4000)
   at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3562)
   at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3615)
   at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3581)
   at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3698)
   at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3589)
   at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3755)
   at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3562)
   at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3615)
   at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3581)
   at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3589)
   at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3562)
   at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3615)
   at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3581)
   at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3731)
   at android.view.ViewRootImpl$ImeInputStage.onFinishedInputEvent(ViewRootImpl.java:3892)
   at android.view.inputmethod.InputMethodManager$PendingEvent.run(InputMethodManager.java:2208)
   at android.view.inputmethod.InputMethodManager.invokeFinishedInputEventCallback(InputMethodManager.java:1849)
   at android.view.inputmethod.InputMethodManager.finishedInputEvent(InputMethodManager.java:1840)
   at android.view.inputmethod.InputMethodManager$ImeInputEventSender.onInputEventFinished(InputMethodManager.java:2185)
   at android.view.InputEventSender.dispatchInputEventFinished(InputEventSender.java:141)
   at android.os.MessageQueue.nativePollOnce(MessageQueue.java)
   at android.os.MessageQueue.next(MessageQueue.java:143)
   at android.os.Looper.loop(Looper.java:122)
   at android.app.ActivityThread.main(ActivityThread.java:5254)
   at java.lang.reflect.Method.invoke(Method.java)
   at java.lang.reflect.Method.invoke(Method.java:372)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:902)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:697)

我的活动从FragmentActivity扩展而来。我只是在我的活动中覆盖onBackPressed方法。在这个onBackPressed方法中,super方法(super.onBackPressed)正在调用。在该超级方法中,访问片段状态。如何避免这次崩溃。?

1 个答案:

答案 0 :(得分:1)

尝试将 onSavedInstanceState 覆盖到您的片段中,就像这样

<bean .*?mobileCfgDataSource.*?>[\S\s]*?<\/bean>

使用 CommitAllowingStateLoss()而不是 commit()