我正在通过改造提出异步请求,在请求中间我最小化应用并使应用崩溃......
我的日志错误:
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);
有人可以帮助我吗?
答案 0 :(得分:0)
很明显,如果你最小化应用程序,那么你将无法替换该片段,因为你的应用程序不在焦点上。抛出java.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;
}
}