title: How to remove previous back stack entry from FragmentManager?
body: <p>I have an activity in which I am switching fragments using following method:</p>
  
  <pre><code>public void setCurrentFragment(Fragment fragment) {
       FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
       transaction.setCustomAnimations(R.anim.slide_left_right_in, R.anim.slide_left_right_out, R.anim.slide_right_left_in, R.anim.slide_right_left_out);
       transaction.replace(R.id.contentFrameLayout, fragment, Integer.toString(fragmentId++));
       transaction.addToBackStack(Integer.toString(fragmentId));
       transaction.commit();
  }
  </code></pre>
  
  <p>My navigation stack looks like this:</p>
  
  <p>N-2 -> N-1 -> N</p>
  
  <p>When certain fragment N is 'opened' I want previous one (N-1) to be removed from the backstack, so when I press 'back' I want N-2 fragment to be restored. </p>
  
  <p>When I call FragmentManager.popBackStack(..) in N fragment it removes N and N-1 fragment. </p>
  
  <p>I have tried to call popBackStack(..) in N-1 fragment right before switching to N fragment. But in that case N-2 fragment is resumed, and only after that N fragment is displayed.</p>
  
  <p>My question is: is there any way to remove previous fragment from backstack without popping current fragment?</p>