0

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
Community
  • 1
  • 1
Iturbo
  • 1
  • 1

1 Answers1

-1

My solution is using EmptyLayout (define yourself) in xml. If there are two or more conditions, show the EmptyLayout, hide the EmptyLayout when it has content (has course).

Floern
  • 33,559
  • 24
  • 104
  • 119
Iturbo
  • 1
  • 1