code: void replaceFragment(Fragment fragment, boolean addToBackStack, boolean popPreviousState) {
          final FragmentManager fragmentManager = getSupportFragmentManager();
          if (popPreviousState) {
              fragmentManager.popBackStack();
          }
  
          final FragmentTransaction ft = fragmentManager.beginTransaction();
          ft.replace(R.id.fragment_container, fragment);
          if (addToBackStack) {
              ft.addToBackStack(null);
          }
          ft.commit();
      }
docs: Replaces a {@link android.support.v4.app.Fragment} in the container.
  
  @param fragment         the new {@link android.support.v4.app.Fragment} used to replace the current.
  @param addToBackStack   true to add transaction to back stack; false otherwise.
  @param popPreviousState true to pop the previous state from the back stack; false otherwise.