title: onCreateOptionsMenu is not called if supportActionBar is null before fragment onCreate
body: <p>If I have one activity with one fragment, <em>fragment1</em>, and use the navigation component to navigate from <em>fragment1</em> to <em>fragment2</em> after setting the supportActionBar to null in onDestroyView, <code>onCreateOptionsMenu</code> is not called even if <code>setHasOptionsMenu(true)</code> is called in onCreate.</p>
  <h2>fragment1.kt:</h2>
  <pre class="lang-kotlin prettyprint-override"><code>...
      override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
          super.onViewCreated(view, savedInstanceState)
          (requireActivity() as AppCompatActivity).setSupportActionBar(toolbar) //kotlin view extension to the Toolbar in fragment1.xml
          view.findViewById&lt;Button&gt;(R.id.without_toolbar_button).setOnClickListener {
              findNavController().navigate(R.id.action_FirstFragment_to_SecondFragment)
          }
      }
  
      override fun onDestroyView() {
          super.onDestroyView()
          (requireActivity() as AppCompatActivity).setSupportActionBar(null)
      }
  ...
  </code></pre>
  <h2>fragment2.kt:</h2>
  <pre class="lang-kotlin prettyprint-override"><code>...
      override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
          super.onViewCreated(view, savedInstanceState)
          (requireActivity() as AppCompatActivity).setSupportActionBar(toolbar)
      }
  
      override fun onCreate(savedInstanceState: Bundle?) {
          super.onCreate(savedInstanceState)
          setHasOptionsMenu(true)
      }
  
      override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
          Toast.makeText(requireActivity(), &quot;onCreateOptionsMenu called!&quot;, Toast.LENGTH_SHORT).show() //this is never called if navigation occurs from fragment1 to this fragment.
          super.onCreateOptionsMenu(menu, inflater)
      }
  ...
  
  </code></pre>
  <h2>fragment1.xml &amp; fragment2.xml:</h2>
  <pre class="lang-xml prettyprint-override"><code>...
      &lt;androidx.appcompat.widget.Toolbar
          android:id=&quot;@+id/toolbar&quot;
          android:layout_width=&quot;match_parent&quot;
          android:layout_height=&quot;wrap_content&quot; ... /&gt;
  ...
  </code></pre>
  <p>The toast is never called. A full demo project demonstrating this can be found and cloned on <a href="https://github.com/Frans-Lukas/OnCreateOptionsMenuNotCalledDemo/tree/master" rel="nofollow noreferrer">github</a>.</p>
  <p>&quot;I had problems with fragments remaining in memory. After adding setSupportActionBar(null), the fragments were garbage collected.&quot; See <a href="https://stackoverflow.com/a/53409237/14053602">this answer</a> from a thread about memory leaks.</p>