I have a very strange error I can't figure out.
I have 1 main Fragment and many secondary fragments. A->(B,C,D,E,F) where Fragment A should always stack on backstack but fragments B,C,D,E should change in and out.
I use these lines of code to do this:
getFragmentManager().executePendingTransactions();
FragmentTransaction transaction = getFragmentManager().beginTransaction();
MyFragment mListFragment = new MyFragment();
transaction.replace(R.id.listFragmentPlaceHold, mListFragment, FRAGMENT_TAG);
if(getFragmentManager().getBackStackEntryCount() == 0)
transaction.addToBackStack(null);
transaction.commit();
The problem is this, if I go from Fragment A to Fragment B and the hit back button everything works correctly. I can do this as many times as I like.
Then, when I go A->B then switch out B a few times, A->(B,C,D) and hit back, I am still good, I get back to A. But, when I have done the above, and then I try to do it again. I again go from A -> B (without restarting activity) and then switch out B to C, D and then hit back, Fragment A is no longer there and I get a Null Pointer Exception.
Could someone please help me out, this is driving me nuts.
I always use getFragmentManager().executePendingTransactions();
before I try to reference Fragment A.
Thank you!