menu inflating calls multiple times at fragment's onCreateOptionsMenu

I use Fragments and when I switch to nested Fragment, which implements public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) my menu inflates quantity of times when I get to that nested Fragment. How can I avoid this? I also implement constructor of Fragment with methods:


When I tried to implement siple solution as:

  • External SDCard file path for Android
  • Android Support Repo 46.0.0 with Android Studio 2.3
  • Got a stacktrace from Android Market that mentions a competitor's app
  • How to resolve the error “ cannot be resolved” when I using the android file '',
  • Difference between base context, application context and activity context
  • Android SDK not found. Make sure that it is installed. If it is not at the default location, set the ANDROID_HOME environment variable
  •  @Override
     public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
         // TODO Add your menu entries here
             inflater.inflate(, menu);
             isInflated = true;
             super.onCreateOptionsMenu(menu, inflater);

    but my menu wasn’t inflate after the screen rotation.

    Related posts:

    Activity transition in Android
    Get the URI of an image stored in drawable
    How to play sounds at accurate periods of time across different devices in Android
    android layout with visibility GONE
    Long press list item to open pop up menu
    Changing coding style due to Android GC performance, how far is too far?
  • onAttach() not called in Fragment
  • How to change color of hamburger icon in material design navigation drawer
  • Android Studio proguard handling in multi-library projects
  • How do I write an android JUnit test when my activity relies on extras passed through an Intent?
  • Performing a UPNP scan is not returning the Philips Hue Bridge
  • How does facebook verify app authenticity with key hash?
  • 3 Solutions collect form web for “menu inflating calls multiple times at fragment's onCreateOptionsMenu”

    I solved it simply by clearing menu before ionflating of it:

         public void   onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
              inflater.inflate(, menu);
              super.onCreateOptionsMenu(menu, inflater);

    Just check the count of menu items. Meaning menu.size()==0 ,no menu items are present,then inflate with layout menu,else don’t inflate at all.

     public void   onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
          if (menu.size() == 0)
          inflater.inflate(, menu);
          super.onCreateOptionsMenu(menu, inflater);

    Use before replace.

    fragment = new EditMyProfile(); fragmentTransactionEditProfile =
    getSupportFragmentManager().popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);
    fragmentTransactionEditProfile.replace(, fragment);

    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.