title: Avoid adding the same fragment several times to backStack
body: <p>I have an activity with 4 fragments. I would like to avoid situations where user click 100 times before exit. When a fragment is set, it's added to back stack.
  For example: User sets fragments in this order: 1, 2, 3, 4 then he sets frag 2 and then 4. My backStack looks like that (fragment 4 is visible): 2, 4, 3, 2, 1 and exit.
  I would like that my backStack looks like: 2, 3, 1 and exit.</p>
  
  <p>I've tried to solve my problem with popBackStackImmediate(string, int flags), like in this post:
  <a href="https://stackoverflow.com/questions/33758712/prevent-the-same-fragment-from-stacking-more-than-once-addtobackstack">Prevent The Same Fragment From Stacking More Than Once ( addToBackStack)</a>
  But my backStack looks like (with 4 visible) 2, 1 and exit.
  I deduced that popBackStackImmediate() is removing stacks on top of the stack which is popped (I hope you know what I mean).</p>
  
  <pre><code>private void setFragment(Fragment fragment) {
  
          String backStateName = fragment.getClass().getName();
  
          FragmentManager manager = getSupportFragmentManager();
          boolean fragmentPopped = manager.popBackStackImmediate (backStateName, 0);
  
          if (!fragmentPopped){ //fragment not in back stack, create it.
              FragmentTransaction ft = manager.beginTransaction();
              ft.replace(R.id.main_frame, fragment);
              ft.addToBackStack(backStateName);
              mMainNav.setItemBackgroundResource(R.color.PopWindowBorder_HomeRenovationfragment);
              ft.commit();
          }
      }
  </code></pre>
  
  <p>I expect to have each fragments no more than one time in the back stack without disrupting the order of the backStack in order to have a back stack which looks like that: 2, 3, 1 and exit. :)</p>