0

I have the following issue. My application has 2 fragments, the first one that is executed show a list of items, when you tap on an item, shows a detail fragment. I also have a NavigationDrawerActivity, with the following methods to handle the stack of fragments.

  private void changeFragment(int pos, Fragment fragment, boolean addToBackStack) {


        Fragment f = getSupportFragmentManager().findFragmentByTag(String.valueOf(pos));
        FragmentManager fragmentManager = getSupportFragmentManager();
        FragmentTransaction ft = fragmentManager.beginTransaction();
        mCacheServices.setmFragmentTag(String.valueOf(pos));
        ft.replace(R.id.container, fragment, String.valueOf(pos));

        if ((addToBackStack)) {
            ft.addToBackStack(STACK_KEY);
        }
        ft.commit();

}

The problem i am facing is when i am in the DetailFragment, and i rotete the device, it goes to the ItemList fragment, which is the firs fragment excuted by the app. What can i do to mantain on the DetailFragment when i rotate the device?

Thanks!

maxi182
  • 33
  • 5

1 Answers1

0

you can save the state of the fragment and then re-create it. Go through this for more details

http://developer.android.com/guide/topics/resources/runtime-changes.html

hope this helps.

PunK _l_ RuLz
  • 621
  • 6
  • 20
  • I tried with setRetainInstance(true); but the method changeFragment is called anyway, and it sets the itemlist fragment again – maxi182 Sep 10 '15 at 17:47
  • I added android:configChanges="orientation|screenSize" on the manifest for the draweractivity where the fragments are conteined. this practice is ok? – maxi182 Sep 10 '15 at 18:06