title: FragmentManager popBackStack doesn't remove fragment
body: <p>I'm implementing menu navigation using Fragments. So I begin with Home, and then users can navigate to diferent sections and details of each section.</p>
  
  <p>When a user changes section, then I call pop on the fragmentmanager backstack until I reach Home, and then load the new section.</p>
  
  <p>This is all working as expected. But I'm getting this problem:</p>
  
  <ol>
  <li>load a section that calls setHasOptionsMenu(true) on onResume()</li>
  <li>loads another section (old section it's suposed to get out of the stack). I see it OK. No menu is shown</li>
  <li>leave the application (for example, go to Android Laucher activity) and then when I return, I see the correct section, but it's showing the Menu of the old Fragment.</li>
  </ol>
  
  <p>I've iterated the backstack and printed each fragment, and there it's not the fragment with the menu. </p>
  
  <p>I put a debug mark on the onResume() method (where the <code>setHasOptionsMenu(true)</code> is flagged) and it indeed enters here, so the Fragment it's still somewhere.</p>
  
  <p>I want to know if I'm doing something wrong and how could I solve it, thx</p>
  
  <p><strong>Update:</strong></p>
  
  <p>I'm using this code to load new fragments</p>
  
  <pre><code>fm.beginTransaction()
      .add(container, sectionFragment.getFragment())
      .addToBackStack(sectionFragment.getFragmentName())
      .commit();
  </code></pre>
  
  <p>And for remove:</p>
  
  <pre><code>private void clearStack(){
  int count = fm.getBackStackEntryCount();
      while(count &gt; 1){
          fm.popBackStack();
          count--;
      }
  }
  </code></pre>
  
  <p><strong>NOTE 1:</strong> I'm using add instead replace because I don't want to loose the state of my fragment when I navigate back from detail section. When I load another different section, then I call clearStack to pop the stack up to 1, and then loads new fragment. At the end, I'm calling executePendingTransactions() to finish to remove the fragments from the transaction.</p>
  
  <p><strong>NOTE 2:</strong> I'm seeing that it is entering on my fragment onDestroy() method, so it is suposed to be destroyed. But I don't know why it is getting called again when the Main activity resumes.</p>