I have code like this to take my currently shown fragment in my activity and show a different fragment. Sometimes the first view is displayed on top of the other view.
What could cause that? Is there a better way to do this?
android.app.FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
fragmentTransaction.remove(from);
fragmentTransaction.commit();
getFragmentManager().executePendingTransactions();
fragmentTransaction = getFragmentManager().beginTransaction();
fragmentTransaction.add(R.id.container, to);
if(showBackButton) {
fragmentTransaction.addToBackStack(to.toString());
}
fragmentTransaction.commit();