Is anyone else getting onCreateOptionsMenu deprecated when running on API 32 or 31?
I did some digging and apparently it is deprecated and we have to use a MenuProvider interface, which after implementing it we can use onCreateMenu and and onMenuItemSelected.
It even states that there is no need to call setHasOptionsMenu(true) (which is also deprecated) and it seems like there is no replacement for this last one. However when I compile the project the ActionBar menu isn't showing. Thoughts?
How do I use the new onCreateMenu from the MenuPRovider interface?
Thank you,
I found the answer.
In your fragment you add a MenuHost
from which you call oncreateMenu()
and onMenuItemSelected()
.
To get the whole answer follow: 'setHasOptionsMenu(Boolean): Unit' is deprecated. Deprecated in Java
It's worth mentioning that Android Studio's docs still show the full documentation for onCreateOptionsMenu()
even though it seems to be deprecated.