2

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?

addy2000
  • 21
  • 1
  • Please check this answer: http://stackoverflow.com/questions/6446961/when-to-use-fragmentmanagerputfragment-and-getfragment – morphium Mar 20 '12 at 05:52
  • Did you find solution? – Suvitruf - Andrei Apanasik Feb 10 '15 at 14:36
  • Doesn't this issue have a solution/workaround ? found it here to : [https://code.google.com/p/android/issues/detail?can=2&start=0&num=100&q=&colspec=ID%20Type%20Status%20Owner%20Summary%20Stars&groupby=&sort=&id=144520](https://code.google.com/p/android/issues/detail?can=2&start=0&num=100&q=&colspec=ID%20Type%20Status%20Owner%20Summary%20Stars&groupby=&sort=&id=144520) – S.Thiongane Apr 15 '15 at 13:16

0 Answers0