4

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,

  • `onCreateOptionsMenu()` [on `Activity` is not presently deprecated](https://developer.android.com/reference/android/app/Activity#onCreateOptionsMenu(android.view.Menu)). What class are you referring to? – CommonsWare May 22 '22 at 12:24
  • I've already wanted to flag this question as dupe before, but it didn't appear exact enough; now this counts as confirmed. Next time please provide relevant code, which makes it easier to find the dupe. – Martin Zeitler May 22 '22 at 13:06

1 Answers1

3

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 shows the full documentation for onCreateOptionsMenu even tough it seems to be deprecated