title: onCreateOptionsMenu() in fragment not replacing ActionBar menus
body: <p>I'm using the NavigationDrawer in my app and replace the fragment when clicking a item in the drawer. My problem I have is that the menu items in the ActionBar are not updated when I change the fragment.</p>
  
  <p>I've followed this tutorial <a href="https://www.grokkingandroid.com/adding-action-items-from-within-fragments/" rel="nofollow">https://www.grokkingandroid.com/adding-action-items-from-within-fragments/</a> closely but it's still not working in my app.</p>
  
  <p>Adding some code snippets of the parent activity and one of the Fragments here. 
  What I need is to display the other menu items of the contact form fragment (R.menu.contactform_send_menu) when the initial fragment gets replaced with ContactFormFragment.java.</p>
  
  <pre><code>public class MainActivity extends FragmentActivity implements ActionBar.OnNavigationListener {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          setTitle(R.string.app_name);
  
          // Set up the action bar to show a dropdown list.
          ActionBar actionBar = getActionBar();
          actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
          actionBar.setDisplayShowTitleEnabled(true);
          actionBar.setDisplayHomeAsUpEnabled(true);
          actionBar.setHomeButtonEnabled(true);
  
          createNavigationDrawer(savedInstanceState);
      }
  
      private final int DRAWER_MAIN = 0;
      private final int DRAWER_CONTACT = 5;
  
      // update the main content by replacing fragments
      private void selectItem(int position) {
          Fragment fragment = null;
          Bundle args = new Bundle();
          boolean isFragment = false;
  
          switch (position) {
          case DRAWER_MAIN:
              fragment = new WelcomeSectionFragment();
              args.putString(WelcomeSectionFragment.ITEM_NAME, dataList.get(position).getItemName());
              args.putInt(WelcomeSectionFragment.IMAGE_RESOURCE_ID, dataList.get(position).getImgResID());
              getActionBar().setTitle(R.string.app_name);
              isFragment = true;
              break;
          case DRAWER_CONTACT:
              fragment = new ContactFormFragment();
              args.putString(ContactFormFragment.ITEM_NAME, dataList.get(position).getItemName());
              args.putInt(ContactFormFragment.IMAGE_RESOURCE_ID, dataList.get(position).getImgResID());
              getActionBar().setTitle(R.string.contactform_title);
              isFragment = true;
              break;
          default:
              break;
          }
  
          if (isFragment) {
              fragment.setArguments(args);
              FragmentManager frgManager = getFragmentManager();
              frgManager.beginTransaction().replace(R.id.content_frame, fragment).commit();
  
              mDrawerList.setItemChecked(position, true);
              setTitle(dataList.get(position).getItemName());
              mDrawerLayout.closeDrawer(mDrawerList);
          }
      }
  
  }
  </code></pre>
  
  <p>and the fragment:</p>
  
  <pre><code>public class ContactFormFragment extends Fragment {
  
      public ContactFormFragment() {
  
      }
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
  
          ca = getActivity();
          Reachability.registerReachability(ca.getApplicationContext());
  
          settings = ca.getSharedPreferences(Konstanten.PREFERENCES_FILE, 0);
          member = new Gson().fromJson(settings.getString(Konstanten.MEMBER_OBJECT, null), Member.class);
  
          latoFontLight = Tools.getFont(ca.getAssets(), "Lato-Light.ttf");
          latoFontBold = Tools.getFont(ca.getAssets(), "Lato-Bold.ttf");
  
          // Update action bar menu items?
          setHasOptionsMenu(true);
      }
  
      @Override
      public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
          // Do something that differs the Activity's menu here
          super.onCreateOptionsMenu(menu, inflater);
  
          menu.clear();
  
          if (Build.VERSION.SDK_INT &gt;= 11) {
              // selectMenu(menu);
              inflater.inflate(R.menu.contactform_send_menu, menu);
          }
      }
  }
  </code></pre>
  
  <p>When debugging I can see that setHasOptionsMenu(true); gets called in onCreate() and I also get into the onCreateOptionsMenu() of ContactFormFragment.java. I just don't understand why the action bar keeps its initial menu items and doesn't replace them. What am I missing?</p>
  
  <p>Thanks for any help.</p>