The following link solved a similar problem: Getting the error "Java.lang.IllegalStateException Activity has been destroyed" when using tabs with ViewPager
But I don't use viewpager in my app and my problem appears when I replace fragment after fragment's onStop()
method. I know it should not to do.
http://www.androiddesignpatterns.com/2013/08/fragment-transaction-commit-state-loss.html
So my question is: How can I solve this condition?
This is my code.the following code is in AsynTask
so when i change tabs, this condition appear fragments' onStop
method will be used before the following code.
ErrorFragment errorFragment = new ErrorFragment();
Bundle bundle = new Bundle();
bundle.putInt("layoutId", R.layout.errorfragment_mycourse_empty);
errorFragment.setArguments(bundle);
transaction.add(R.id.framelayout_mycoursestudied, errorFragment);
transaction.commitAllowingStateLoss();//error code