Skip to content Skip to sidebar Skip to footer

FragmentTransaction Add Fragment After Replace Old Fragment But OnDestroyView Called

I replaced FragmentA : FragmentManager fm = MainActivity.getGlobal().getSupportFragmentManager(); FragmentTransaction ft = fm.beginTransaction(); ft.addToBackStack(fragmentA.get

Solution 1:

A call to replace() is analogous to calling remove() on A and them calling add() on B hence it is not possible to save A when you replace it it's onDestroy(), onDestroyView() etc will be called.

But instead of calling replace() you can call add() for B add B on top of A without removing A and add B to back stack to navigate to A on back press

Have a good day , Ali


Post a Comment for "FragmentTransaction Add Fragment After Replace Old Fragment But OnDestroyView Called"