title: Menu object is coming null when it is getting called as a callback function
body: <p>I have a requirement of placing a progressbar in the actionbar/toolbar. I am able to do it by following this link(<a href="http://www.michenux.net/android-refresh-item-action-bar-circular-progressbar-578.html" rel="nofollow">http://www.michenux.net/android-refresh-item-action-bar-circular-progressbar-578.html</a>).
  However I am facing an issue in order to show and hide the progressbar, following the callback design pattern which I have used here. Below is code snippet -</p>
  
  <pre><code>    public interface ICallBack {
          void setRefreshActionButtonState(boolean b);
      }
  
      public class MyFragment extends Fragment implements View.OnClickListener, ICallBack {
          private Menu optionsMenu;
  
          @Override
          public void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
              setHasOptionsMenu(true);
          }
  
          @Override
          public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
              webView = (WebView) findViewById(R.id.main_web);
  
              webView.setWebViewClient(new MyWebViewClient());    
              webView.loadUrl("http://stackoverflow.com/");
          }
  
          @Override
          public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
              this.optionsMenu = menu;
              getActivity().getMenuInflater().inflate(R.menu.menu_home_base, menu);
          }
  
          @Override
          public boolean onOptionsItemSelected(MenuItem item) {
              int id = item.getItemId();
              if (id == R.id.action_refresh) {
                  // Logic to load the webview again 
              }
              return super.onOptionsItemSelected(item);
          }
  
          @Override
          public void setRefreshActionButtonState(boolean refreshing) {
              if (optionsMenu != null) {
                  final MenuItem refreshItem = optionsMenu.findItem(R.id.action_refresh);
                  if (refreshItem != null) {
                      if (refreshing) {
                          refreshItem.setActionView(R.layout.toolbar_indeterminate_progress);
                      } else {
                          refreshItem.setActionView(null);
                      }
                  }
              }
          }
      }
  
  
  public class MyWebViewClient extends WebViewClient {
          ICallBack callBack;
          public MyWebViewClient(Activity context) {
              callBack = new MyFragment();
          }
  
          @Override
          public boolean shouldOverrideUrlLoading(WebView view, String url) {
              view.loadUrl(url);
              return true;
          }
  
          @Override
          public void onPageStarted(WebView view, String url, Bitmap favicon) {
              super.onPageStarted(view, url, favicon);
              callBack.setRefreshActionButtonState(true);//Showing the progressbar
          }
  
          @Override
          public void onPageFinished(WebView view, String url) {
              super.onPageFinished(view, url);
              callBack.setRefreshActionButtonState(false);//Hiding the progressbar
          }
      }
  </code></pre>
  
  <p>When <strong>setRefreshActionButtonState()</strong> gets call then I am getting <strong>optionsMenu</strong> value as <strong>null</strong>, resulting not able to show and hide the progressbar.  </p>
  
  <p>Can someone help me to figure out that where I am doing wrong.</p>
  
  <p>Thanks,    </p>