title: Update menu item after screen rotation
body: <p>I'd like to show a progress bar when a user clicks a menu item in the action bar and launch an AsyncTask that does some work. When finished the task restore the menu. Here is my code:</p>
  
  <pre><code>public class DevicesActivity extends FragmentActivity {
  ...
  
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {   
      switch (item.getItemId()) {
              case R.id.my_menu_action:
                  MyTask task = new MyTask();
                  task.execute(item);
                  // Show a progress bar instead of default actionview
                  item.setActionView(R.layout.progress_circle);
                  item.expandActionView();
                  return true;
           }
          return super.onOptionsItemSelected(item);
       }
  
      ...
  
      private class MyTask extends AsyncTask&lt;MenuItem, Object, Object&gt; {
          MenuItem menuItem;
  
          protected Object doInBackground(MenuItem... items) {
              item = items[0];
  
              try {
                  Thread.sleep(2000);
              }
              catch (Exception e) {}
  
              return null;
          }
  
          protected void onPostExecute(Object result) {
              // Restore default action view
              if (menuItem != null) {
                  menuItem.collapseActionView();
                  menuItem.setActionView(null);
              }
          }
      }
  }
  </code></pre>
  
  <p>The problem occurs when the activity is recreated (for example when rotating the screen) because the progress bar isn't shown and the menuItem reference inside MyTask becomes invalid. So the questions are:
  1) When creating the menu (onCreateOptionsMenu method) how can I know if the menuItem was clicked ?
  2) In onPostExecute how can I retrieve a valid reference to a MenuItem object ?</p>