In my application there is a FrameLayout
on which I am adding various fragments
FragmentManager fm = getSupportFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
ft.replace(R.id.fragment_content, fragment, fargmentTag);
ft.commit();
Now it seems when I use the ft.replace(R.id.fragment_content, fragment, fargmentTag);
and then in other places call
getSupportFragmentManager().findFragmentByTag(fargmentTag);
I always get null
.
However if I use add
instead of replace
this problem is fixed but another problem appears that each fragment is added ontop of the other fragment and i can see the other fragments below.
I would prefer to use replace
, but I need the saved fragment state. Also to be noted I am not using addToBackStack
.