title: Android menu item visibility change in runtime
body: <p>I am trying to hide an action bar menu item for a certain period of time while a task is being performed in the background of the running <code>activity</code>.</p>
  
  <p>First in the activity's <code>onPrepareOptionsMenu</code> method, I retrieve the <code>MenuItem</code> instance as a field.</p>
  
  <pre><code>public void onPrepareOptionsMenu(final Menu menu) {
      super.onPrepareOptionsMenu(menu);
      // Retrieve and show the contextual settings menu item
      mContextualSettings = menu.findItem(R.id.item_menu_contextual_settings);
      mContextualSettings.setVisible(true);
  }
  </code></pre>
  
  <p>Later I use that field to make it invisible and visible again(by using the setVisible method).</p>
  
  <p>I was wondering if this is a good approach or should I somehow use the <code>invalidateOptionsMenu()</code> to make it visible again? Can I ran into null pointer exceptions?</p>
  
  <p>Thanks.</p>