title: How to get around timing issue in Android
body: <p>I'm storing one of the menu items from my activity as a class field, when inside <code>onCreateOptionsMenu()</code>. </p>
  
  <pre><code>_myMenuItem = (MenuItem) findViewById(R.id.menu_item);
  </code></pre>
  
  <p>But in <code>onCreate()</code> I call an async method, and the result of that dictates whether I should make the visibility true or false on said menu item; for example:</p>
  
  <pre><code>if (someCondition) {
    _myMenuItem.setVisible(true);
  }
  </code></pre>
  
  <p>The problem is sometimes the async method completes (and that above code is called) before the menu is inflated, causing a null pointer exception.</p>
  
  <p>How can I resolve this timing issue? Ideally without putting the async call inside <code>onCreateOptionsMenu()</code> if anyone knows of a good way. Thanks</p>