title: Custom option Menu
body: <p>I have created one custom menu in fragment, and it is working fine, but problem is when i go back, that menu is display in all activity and fragment, i dont want it to display in all, so help me out.</p>
  
  <pre><code>public class DriverLogDetialsFragment extends Fragment {
              private MainActivity mainActivity;
  
              public DriverLogDetialsFragment() {
                  // Required empty public constructor
              }
  
              public static DriverLogDetialsFragment newInstance(MainActivity mainActivity) {
                  DriverLogDetialsFragment fragment = new DriverLogDetialsFragment();
                  fragment.mainActivity = mainActivity;
                  return fragment;
              }
  
              @Override
              public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
                  // Inflate the layout for this fragment
                  //setHasOptionsMenu(true);
                  return inflater.inflate(R.layout.fragment_driverlog_detials, container, false);
              }
  
              @Override
              public void onCreate(Bundle savedInstanceState) {
                  super.onCreate(savedInstanceState);
                  setHasOptionsMenu(true);
              }
  
              @Override
              public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
                  super.onCreateOptionsMenu(menu, inflater);
                  inflater.inflate(R.menu.menu_log_detials, menu);
  
              }
  
              @Override
              public boolean onOptionsItemSelected(MenuItem item) {
                  int id = item.getItemId();
  
                  if (id == R.id.action_email) {
                      View view = LayoutInflater.from(getActivity()).inflate(R.layout.dialog_email, null);
  
                      AlertDialog.Builder bulider = new AlertDialog.Builder(getContext());
                      bulider.setView(view);
                      bulider.setCancelable(false);
                      bulider.setPositiveButton("Send", new DialogInterface.OnClickListener() {
                          @Override
                          public void onClick(DialogInterface dialog, int which) {
                              dialog.dismiss();
                          }
                      });
                      bulider.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                          @Override
                          public void onClick(DialogInterface dialog, int which) {
                              dialog.dismiss();
                          }
                      });
                      bulider.show();
                  }
  
                  return super.onOptionsItemSelected(item);
              }
  
  
          }
  </code></pre>