The following is a part of the code i wrote to replace fragments using FragmentManager.
FragmentManager mFragmentManager = getFragmentManager();
if(activeFragment!=null) {
mFragmentManager.putFragment(fragmentBundle,oldTabId + FRAGMENT_PREF, activeFragment);
System.out.println((oldTabId + FRAGMENT_PREF) + " of type " + activeFragment.getClass().getSimpleName() + " inserted to Bundle");
}
if(fragmentBundle.containsKey(newTabId + FRAGMENT_PREF)) {
activeFragment = mFragmentManager.getFragment(fragmentBundle, newTabId + FRAGMENT_PREF);
System.out.println((newTabId + FRAGMENT_PREF) + " of type " + activeFragment.getClass().getSimpleName() + " retrieved from Bundle");
} else {
//create new fragment otherwise
}
if(activeFragment!=null) {
//replace old fragment with new fragment.
}
After inserting two fragments, any getFragment (for any key) gives a fragment of the type of the second one and also onCreateView doesnt get called.
What am I doing wrong?