My project contains two fragment :
fragmentA
when a c
I will suggest using the fragment replacement with Tag to produce the same result .
Add the fragment B to activity with tag
fragmentTransaction.replace(R.id.main_fragment_container, new FragmentB(),"TAG_B");
Fragment A -> Fragment B [onBackPressed] -->Fragment A Override the onBackPressed() in the Activity files where ,
// check for fragment B and you are viewing fragment B
if (getSupportFragmentManager().findFragmentByTag("TAG_B")!=null)
{
fragmentTransaction.replace(R.id.main_fragment_container, new FragmentA(),"TAG_A");
}
addToBackStack("TAG") and popBackStackImmediate("TAG") always revert to fragment condition without any data in the UI right before fragment is created or added to activity !