2017-09-04 33 views
1
後無法執行此操作

我正在與改造一個異步請求,...最小化應用上產生的請求,我儘量減少應用程序和崩潰的應用程序中間的onSaveInstanceState

我的日誌錯誤:

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

這很明顯,如果你最小化應用程序,那麼你將無法替換片段,因爲你的應用程序沒有焦點& throw 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; 
    } 
} 
相關問題