1

我正在通过改造发出异步请求,在请求中间我最小化应用程序并使应用程序崩溃......

我的日志错误:

java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
at android.support.v4.app.FragmentManagerImpl.checkStateLoss(FragmentManager.java:1842)
at android.support.v4.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:1860)
at android.support.v4.app.BackStackRecord.commitInternal(BackStackRecord.java:650)
at android.support.v4.app.BackStackRecord.commit(BackStackRecord.java:609)
at br.com.ole.oleconsignado.util.ActivityUtils.replaceFragmentToActivityWithBackStack(ActivityUtils.java:109)
at br.com.ole.oleconsignado.ui.fragment.init.LoginFragment.notifyGetProspectSuccess(LoginFragment.java:410)
at br.com.ole.oleconsignado.ui.presenter.LoginPresenter$4.onSuccess(LoginPresenter.java:91)
at br.com.ole.oleconsignado.ui.presenter.LoginPresenter$4.onSuccess(LoginPresenter.java:88)
at br.com.ole.oleconsignado.network.RestCallback.onResponse(RestCallback.java:24)
at retrofit2.ExecutorCallAdapterFactory$ExecutorCallbackCall$1$1.run(ExecutorCallAdapterFactory.java:68)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6165)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:888)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:778)

如果请求返回成功,这是我调用的方法:

ActivityUtils.replaceFragmentToActivityWithBackStack(getFragmentManager(), IncompleteStatusFragment.newInstance(mLogin.getCustomerId(), mCustomer, prospect, mLogin), R.id.container_login);

有人能帮我吗?

4

1 回答 1

0

很明显,如果您最小化应用程序,那么您将无法替换片段,因为您的应用程序不在 focus & throwjava.lang.IllegalStateException中。如果该标志为真,您应该可能在您的活动的 onResume 中维护一个标志,然后替换该片段。

喜欢

@Override
public void onPause() {
   mIsActivityVisible = false;
}

@Override
public void onResume() {
   mIsActivityVisible = true;
   if(mShouldReplaceFragmentOnResume) {
      mShouldReplaceFragmentOnResume = false;
      // replace fragment
   }
}

// On Success response
onSuccessOfYourCall() {
   if(mIsActivityVisible) {
       //replace fragment
   } else {
       mShouldReplaceFragmentOnResume = true;
   }
}
于 2017-09-04T14:23:26.237 回答