title: How to add/remove menu items at runtime in ICS?
body: <p>I'm using the ActionBarCompat sample that comes with the SDK. My activity used to have menu items that would change based on the state of the activity. I would modify the menu like so in <code>onPrepareOptionsMenu()</code>:</p>
  
  <pre><code>@Override
  public boolean onPrepareOptionsMenu(Menu menu) {
      menu.clear();
  
      if (some condition) {
          menu.add(...);
      }
      ...
  }
  </code></pre>
  
  <p>In ICS however, I believe we're supposed to modify menu items by calling <code>invalidateOptionsMenu()</code> and then our <code>onCreateOptionsMenu()</code> is called again. Here we can remove menu items (not add them). So then we might end up with something like this:</p>
  
  <pre><code>@Override
  public boolean onCreateOptionsMenu(Menu menu) {
      if (SDK &gt;= 11) {
          // full menu is reloaded from xml every time we 
          // called invalidateOptionsMenu(), so we have a
          // fresh menu here again.
      }
  }
  
  @Override
  public boolean onPrepareOptionsMenu(Menu menu) {
      if (SDK &gt;= 11) {
          // we can remove items depending on our state, 
          // but not add any, that's ok.
      }
      else {
          // we only have our original menu instance here,
          // so if we previously had called menu.remove(),
          // we need to call menu.add() here:
          if (foo == true) {
              menu.remove(R.id.menu_item_foo);
          } else {
              menu.add(R.id.menu_item_foo, ...);
          }
      }
  }
  </code></pre>
  
  <p>This seems a bit awkward, </p>
  
  <p>Thanks</p>