Event when the FragmentTransaction is completed
You don't need to wait for the fragment transaction to complete, You can call
getSupportFragmentManager().executePendingTransactions();
after your commit() function call.
This will ensure that the transaction is complete.
Hei! Try this:
private OnBackStackChangedListener backStackListener = new OnBackStackChangedListener() {
@Override
public void onBackStackChanged() {
String name = "";
int position = getSupportFragmentManager().getBackStackEntryCount();
if(position!=0){
FragmentManager.BackStackEntry backEntry=getSupportFragmentManager().getBackStackEntryAt(position-1);
name=backEntry.getName();
}
if(position==0){
mainActionBar();
}
else if(name=="someWord"){
mainActionBar2();
}
else{
mainActionBar3();
}
}
};
getSupportFragmentManager().addOnBackStackChangedListener(backStackListener);
And in Transaction add tag to backStack like this:
getSupportFragmentManager().beginTransaction()
.replace(R.id.main, SomeFragment.newInstance(some argument))
.addToBackStack("someWord").commit();