title: Inflating only a specific action bar menu
body: <p>I have an action bar menu defined in my main activity. Now, one of the fragments I am using in that activity has its own action bar menu but when I click on the menu option, I get both the fragment's as well as the activity's menu items. How to ensure that only that fragment's menu item is displayed?</p>
  
  <p>My java code for that fragment is:</p>
  
  <pre><code>public class ProfileD extends Fragment {
  
  TextView tv_named, tv_genderd, tv_cfd, tv_aged, tv_biod, tv_statusd;
  ImageView imageView_dp;
  
  public ProfileD() {
      // Required empty public constructor
  }
  
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
                           Bundle savedInstanceState) {
      // Inflate the layout for this fragment
      View rootView = inflater.inflate(R.layout.fragment_profile_d, container, false);
  
      tv_named = (TextView)rootView.findViewById(R.id.tv_named);
      tv_genderd = (TextView)rootView.findViewById(R.id.tv_genderd);
      tv_cfd= (TextView)rootView.findViewById(R.id.tv_cfd);
      tv_aged = (TextView)rootView.findViewById(R.id.tv_aged);
      tv_biod = (TextView)rootView.findViewById(R.id.tv_biod);
  
      tv_statusd = (TextView) rootView.findViewById(R.id.tv_statusd);
  
      imageView_dp = (ImageView)rootView.findViewById(R.id.imageView_dp);
      setHasOptionsMenu(true);
  
      return rootView;
  }
  
  @Override
  public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
  
      super.onCreateOptionsMenu(menu, inflater);
  
      getActivity().getMenuInflater().inflate(R.menu.profile_menu, menu);
  }
  
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
      // Handle action bar item clicks here. The action bar will
      // automatically handle clicks on the Home/Up button, so long
      // as you specify a parent activity in AndroidManifest.xml.
      int id = item.getItemId();
  
      //noinspection SimplifiableIfStatement
      if (id == R.id.edit_profile) {
  
          Intent intent = new Intent(getContext(),PersonalDetails.class);
          intent.putExtra("Edit",1);
          startActivity(intent);
  
          return true;
      }
  
      return super.onOptionsItemSelected(item);
  }
  
  @Override
  public void onResume() {
      super.onResume();
  
      AppCompatActivity appCompatActivity = (AppCompatActivity)getActivity();
      ActionBar actionBar = appCompatActivity.getSupportActionBar();
      actionBar.setTitle("Profile");
  }
  }
  </code></pre>
  
  <p>The xml file for the menu is:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;menu xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"&gt;
  
  &lt;item
      android:id="@+id/edit_profile"
      android:orderInCategory="100"
      android:title="Edit"
      app:showAsAction="never" /&gt;
  
  &lt;/menu&gt;
  </code></pre>