0

I have two fragments that I change back and forth depending on the current users state. I use the following on the code below and it works great when using the app pretty much all the time. The only time i get a force close though is when i log the user out, log back in, user changes their state, and then I get a "java.lang.IllegalStateException: Activity has been destroyed". The error points to the last line in the code but I'm still confused why it happens only in that one time.

    FrameLayout fLayout = (FrameLayout) rootView.findViewById(R.id.frameLayoutNC);
    fLayout.removeAllViews();

    android.support.v4.app.FragmentManager fragmentManager = getChildFragmentManager();
    android.support.v4.app.FragmentTransaction ft = fragmentManager.beginTransaction();

    CCF newFragment = new CCF();
    ft.replace(R.id.frameLayoutNotCharging, newFragment);
    ft.setTransition(android.support.v4.app.FragmentTransaction.TRANSIT_NONE);
    ft.addToBackStack(null);
    ft.commitAllowingStateLoss();
mitch94
  • 236
  • 1
  • 3
  • 11
  • What class and method contains this code? – Code-Apprentice Sep 03 '16 at 22:09
  • Please share your activity class where you are transitioning the fragment and your stacktrace as well – Gaurav Sarma Sep 03 '16 at 22:19
  • So I have a tab bar and one of the tabs is fragment1. when the user state changes, i call that code i posted above that switches it from fragment1 to fragment2. The tab itself doesn't actually change, its just the view on that one single tab that changes. both classes extends Fragment. The class itself just does a bunch of firebase db parsing so there isn't really anything in there. Would there be a better approach then the one i implemented? – mitch94 Sep 03 '16 at 22:30
  • Have a close look at [this](http://stackoverflow.com/questions/7469082/getting-exception-illegalstateexception-can-not-perform-this-action-after-onsa/10261438#10261438), it will help you. – isamirkhaan1 Sep 03 '16 at 22:32

1 Answers1

0

To answer my own question, I never seemed to actually get it to work. I moved towards a 1 fragment screen with 2 linear layouts inside of it and changed the visibility of those when needed.

mitch94
  • 236
  • 1
  • 3
  • 11