I have Activity A and B, both inherits from a BaseActivity class. Activity A handles several fragments, and from one of them Activity B is started. In the onCreate method of Activiy B I call the following method :
addFragmentWithAnimation(ExampleFragment.newInstance(), R.anim.custom_slide_in_bottom, 0 , true);
that is received by the Base Activity class:
@Override
public void addFragmentWithAnimation(Fragment fragment, int i, int i1, boolean isInBackStack) {
FragmentManager fManager = getSupportFragmentManager();
fManager.executePendingTransactions();
FragmentTransaction transaction = fManager.beginTransaction();
transaction.setCustomAnimations(i, i1);
transaction.add(R.id.container, fragment);
if (isInBackStack) {
transaction.addToBackStack(fragment.getClass().getCanonicalName());
}
transaction.commit();
}
so, a ExampleFragment is added to the activity and is displayed with a slide in from the bottom animation. Then ExampleFragment call to the same method to a Example2Fragment, but before I remove it as the following
@Override
public void closeFragmentWithAnimation(Fragment fragment, int i, boolean isInBackStack) {
FragmentManager fManager = getSupportFragmentManager();
fManager.executePendingTransactions();
FragmentTransaction transaction = fManager.beginTransaction();
transaction.setCustomAnimations(0, i);
transaction.remove(fragment);
if (isInBackStack) {
transaction.addToBackStack(fragment.getClass().getCanonicalName());
}
transaction.commit();
}
by calling it from Example2Fragment. I'd like to emphasize that both transactions are added to the backstack So far so good, the problem is when I press the back stack button. It returns to a blank activity with no fragment, when the expected behaviour is landing on ExampleFragment
how really works the back stack? What I'm missing here?
thanks