I have a customer code. There is only one activity for all of the fragments i.e. the single activity is managing all the fragments.
This activity contains the follow
Your answers are deprecated. If you don't want to add fragments to back stack, you should use below snippet of code:
public static void replaceFragment (@NonNull FragmentManager fragmentManager,
@NonNull Fragment fragment, int frameId){
checkNotNull(fragmentManager);
checkNotNull(fragment);
FragmentTransaction transaction = fragmentManager.beginTransaction();
transaction.replace(frameId, fragment);
transaction.disallowAddToBackStack(); // <-- This makes magic!
transaction.commit();
}
Below you have cute example of how use it:
GameFragment fragment = GameFragment.newInstance(mGameObject, currentQuestion);
ActivityUtils.replaceFragment(getFragmentManager(), fragment, R.id.main);