I’m using the v4 compatibility library and switch to new fragments like this:
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.setCustomAnimations(R.anim.fade_in, R.anim.fade_out);
transaction.replace(R.id.contentFragmentContainer, event.getFragmentClass().newInstance(), FRAGMENT_CONTENT);
transaction.addToBackStack(fragmentTransactionName);
transaction.commit();
Now, when I want to return to a previous fragment programmatically without polluting the user’s back stack with new fragment transactions, I use popBackStackImmediate():
if (fragmentManager.popBackStackImmediate(fragmentTransactionName, 0)) {
return;
}
// apparently popping back to that fragment was not successful,
// make a regular transaction now
This works all fine as is, despite that the animations that have been used to animate to one of the popped fragments are not reversed. I also tried to use transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE) beforehand, but this did not even show a transition when the regular transaction took place, neither does it show on reverse.
What am I doing wrong?
I’d say I have to Read The Fine Manual (TM) better:
(Source)