Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

onCreateOptionsMenu deprecated [duplicate]

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,

like image 703
David Rajchenberg Avatar asked Jun 25 '26 02:06

David Rajchenberg


1 Answers

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.

like image 195
David Rajchenberg Avatar answered Jun 26 '26 16:06

David Rajchenberg