0

When i move from Fargment A to another Fragment B and come back to the Fragment A, I do not want to create or inflate fragment A view again. How to maintain and restore the state of Fragment A.

Below is the code, how i am moving from fragment A to Fragment B.

FragmentManager fragmentManager=getActivity().getSupportFragmentManager();
                FragmentTransaction fragmentTransaction=fragmentManager.beginTransaction();

                FragmentB fragmentB=new FragmentB();

                fragmentTransaction.replace(R.id.frameLayoutmainActivity, fragmentB);
                fragmentTransaction.addToBackStack("previous");
                fragmentTransaction.commit();

and when come back to fragment A, on the back button click....

FragmentManager fm = getActivity().getSupportFragmentManager();
            fm.popBackStack();

but the problem is onCreateView() always called and view inflates again.I do not want to inflate view again.

Manju Kumari
  • 107
  • 1
  • 9
  • 2
    http://stackoverflow.com/questions/15313598/once-for-all-how-to-correctly-save-instance-state-of-fragments-in-back-stack – jitain sharma Jul 31 '14 at 06:58
  • http://stackoverflow.com/questions/11353075/how-can-i-maintain-fragment-state-when-added-to-the-back-stack and http://stackoverflow.com/questions/14752895/switch-fragments-while-maintaining-state – MysticMagicϡ Jul 31 '14 at 06:59
  • I have fixed this issue by using add() on the place of replace().Now its Working fine for me. – Manju Kumari Aug 05 '14 at 12:18

0 Answers0