title: Toolbar Menu showing in wrong fragment
body: <p>My main_activity have 2 fragments -> Parent and Child as follow :</p>
  
  <p><a href="https://imgur.com/ws9BRWR" rel="nofollow noreferrer">https://imgur.com/ws9BRWR</a></p>
  
  <p>each fragment should have their own actionbar and their own menu.</p>
  
  <p>my question are : why is the menu that supposedly shown in child fragment mixed together into the parent fragment?</p>
  
  <p>Child-Menu-1 and Child-Menu-2 supposed to be inside menu in child fragment </p>
  
  <p>this is what i have done : </p>
  
  <p>fragmentParent :</p>
  
  <pre><code>@Nullable
  @Override
  public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
      View view = inflater.inflate(R.layout.activity_parent, container, false);
      setHasOptionsMenu(true);
  
      Toolbar myToolbar = (Toolbar) view.findViewById(R.id.tb_parent);
      ((AppCompatActivity)getActivity()).setSupportActionBar(myToolbar);
      ((AppCompatActivity)getActivity()).getSupportActionBar().setTitle("PARENT");
      //((AppCompatActivity)getActivity()).getSupportActionBar().setDisplayShowTitleEnabled(false);
  
      return view;
  }
  
  @Override
  public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
      super.onCreateOptionsMenu(menu, inflater);
      inflater.inflate(R.menu.menu_parent, menu);
  }
  </code></pre>
  
  <p>fragmentChild :</p>
  
  <pre><code>@Nullable
  @Override
  public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
      View view = inflater.inflate(R.layout.activity_child, container, false);
      setHasOptionsMenu(true);
  
      Toolbar myToolbar = (Toolbar) view.findViewById(R.id.tb_child);
      ((AppCompatActivity)getActivity()).setSupportActionBar(myToolbar);
      ((AppCompatActivity)getActivity()).getSupportActionBar().setTitle("CHILD");
      //((AppCompatActivity)getActivity()).getSupportActionBar().setDisplayShowTitleEnabled(false);
  
      return view;
  }
  
  @Override
  public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
      super.onCreateOptionsMenu(menu, inflater);
      inflater.inflate(R.menu.menu_child, menu);
  }
  </code></pre>
  
  <p>what i have tried already : </p>
  
  <ul>
  <li><p>move the getSupportActionBar into onViewCreated &lt;--- same result</p></li>
  <li><p>move the inflate to onPrepareOptionsMenu &lt;--- same result</p></li>
  </ul>
  
  <p>i noticed that if i remove the menu from the parent fragment, the menu on the child show up correctly, problem only if i try to load each with their own menu.</p>
  
  <p>when i debug the apps, the sequence called are :</p>
  
  <ol>
  <li><p>calling child fragment onCreateView </p></li>
  <li><p>calling parent fragment onCreateView </p></li>
  <li><p>calling child onCreateOptionsMenu</p></li>
  <li><p>calling parent onCreateOptionsMenu</p></li>
  </ol>
  
  <p>so i'm suspecting the problem is in the onCreateOptionMenu where the inflater inflate the wrong fragment. </p>
  
  <p>i already do a lot of searching inside SO and google, but no question seems similar to my case.</p>
  
  <p>thank you very much in advance!!</p>
  
  <p>==========================================================================</p>
  
  <p>further examination and testing... so i commented out the creating of the toolbar from the parent fragment :</p>
  
  <p>fragmentParent :</p>
  
  <pre><code>@Nullable
  @Override
  public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
      View view = inflater.inflate(R.layout.activity_parent, container, false);
      setHasOptionsMenu(true);
  
      //Toolbar myToolbar = (Toolbar) view.findViewById(R.id.tb_parent);
      //((AppCompatActivity)getActivity()).setSupportActionBar(myToolbar);
      //((AppCompatActivity)getActivity()).getSupportActionBar().setTitle("PARENT");
      //((AppCompatActivity)getActivity()).getSupportActionBar().setDisplayShowTitleEnabled(false);
  
      return view;
  }
  
  @Override
  public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
      super.onCreateOptionsMenu(menu, inflater);
      inflater.inflate(R.menu.menu_parent, menu);
  }
  </code></pre>
  
  <p>fragmentChild :</p>
  
  <pre><code>@Nullable
  @Override
  public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
      View view = inflater.inflate(R.layout.activity_child, container, false);
      setHasOptionsMenu(true);
  
      Toolbar myToolbar = (Toolbar) view.findViewById(R.id.tb_child);
      ((AppCompatActivity)getActivity()).setSupportActionBar(myToolbar);
      ((AppCompatActivity)getActivity()).getSupportActionBar().setTitle("CHILD");
      //((AppCompatActivity)getActivity()).getSupportActionBar().setDisplayShowTitleEnabled(false);
  
      return view;
  }
  
  @Override
  public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
      super.onCreateOptionsMenu(menu, inflater);
      inflater.inflate(R.menu.menu_child, menu);
  }
  </code></pre>
  
  <p>Result : </p>
  
  <p><a href="https://imgur.com/wYVdsvH" rel="nofollow noreferrer">https://imgur.com/wYVdsvH</a></p>
  
  <p>all menu item show up in the child fragment, why is the parent fragment onCreateOptionMenu getting called while there's no toolbar is declared? </p>
  
  <p>i'm hitting wall here :(</p>