I have a 3 fragments in an activity when the a tablet is held in portrait. However I only have 2 of these fragments when in landscape. The problem I am having is when going from portrait to landscape the activity is creating the 3rd fragment. I receive and error as this fragment cannot be created.
I have worked out that this fragment is being created because it is in the back stack.
I have tried to remove the fragment in the onDestroy method by using
FragmentTransaction f = fragmentManager.beginTransaction();
mf = MapFragment.newInstance(1, true);
ft = fragmentManager.beginTransaction();
You add to the back state from the
FragmentTransaction and remove from the backstack using
FragmentManager pop methods:
FragmentManager manager = getActivity().getSupportFragmentManager(); FragmentTransaction trans = manager.beginTransaction(); trans.remove(myFrag); trans.commit(); manager.popBackStack();