MenuHostHelper

public class MenuHostHelper
extends Object

java.lang.Object
   ↳ androidx.core.view.MenuHostHelper


Helper class for implementing MenuHost.

Summary

Public constructors

MenuHostHelper(Runnable onInvalidateMenuCallback)

Construct a new MenuHostHelper.

Public methods

void addMenuProvider(MenuProvider provider)

Adds the given MenuProvider to the helper.

void addMenuProvider(MenuProvider provider, LifecycleOwner owner, Lifecycle.State state)

Adds the given MenuProvider to the helper once the given LifecycleOwner reaches the given Lifecycle.State.

void addMenuProvider(MenuProvider provider, LifecycleOwner owner)

Adds the given MenuProvider to the helper.

void onCreateMenu(Menu menu, MenuInflater menuInflater)

Inflates the entire Menu, which will include all MenuItems provided by all current MenuProviders.

boolean onMenuItemSelected(MenuItem item)

Called whenever one of the menu items from any of the current MenuProviders is selected.

void removeMenuProvider(MenuProvider provider)

Removes the given MenuProvider from the helper.

Inherited methods

Public constructors

public MenuHostHelper (Runnable onInvalidateMenuCallback)

Construct a new MenuHostHelper.

Parameters
onInvalidateMenuCallback Runnable: callback to invalidate the menu whenever there may be a change to it

Public methods

addMenuProvider

public void addMenuProvider (MenuProvider provider)

Adds the given MenuProvider to the helper.

Parameters
provider MenuProvider: the MenuProvider to be added

addMenuProvider

public void addMenuProvider (MenuProvider provider, 
                LifecycleOwner owner, 
                Lifecycle.State state)

Adds the given MenuProvider to the helper once the given LifecycleOwner reaches the given Lifecycle.State. This MenuProvider will be removed once the given LifecycleOwner goes down from the given Lifecycle.State or receives an ERROR(/Lifecycle.Event.ON_DESTROY) event.

Parameters
provider MenuProvider: the MenuProvider to be added

owner LifecycleOwner: the Lifecycle owner whose state will determine the removal of the provider

state Lifecycle.State: the Lifecycle.State to check for automated addition/removal

addMenuProvider

public void addMenuProvider (MenuProvider provider, 
                LifecycleOwner owner)

Adds the given MenuProvider to the helper. This MenuProvider will be removed once the given LifecycleOwner receives an ERROR(/Lifecycle.Event.ON_DESTROY) event.

Parameters
provider MenuProvider: the MenuProvider to be added

owner LifecycleOwner: the Lifecycle owner whose state will determine the removal of the provider

onCreateMenu

public void onCreateMenu (Menu menu, 
                MenuInflater menuInflater)

Inflates the entire Menu, which will include all MenuItems provided by all current MenuProviders.

Parameters
menu Menu: the menu to inflate all the menu items into

menuInflater MenuInflater: the inflater to be used to inflate the menu

onMenuItemSelected

public boolean onMenuItemSelected (MenuItem item)

Called whenever one of the menu items from any of the current MenuProviders is selected.

Parameters
item MenuItem: the menu item that was selected

Returns
boolean true to indicate the menu processing was consumed by one of the MenuProviders, false otherwise.

removeMenuProvider

public void removeMenuProvider (MenuProvider provider)

Removes the given MenuProvider from the helper.

Parameters
provider MenuProvider: the MenuProvider to be removed