# MenuHost

Artifact: [androidx.core:core](https://developer.android.com/jetpack/androidx/releases/core) [View Source](https://cs.android.com/search?q=file:androidx/core/view/MenuHost.java+class:androidx.core.view.MenuHost) Added in [1.7.0](https://developer.android.com/jetpack/androidx/releases/core#1.7.0)

*** ** * ** ***


```
public interface MenuHost
```

<br />

Known direct subclasses [ComponentActivity](https://developer.android.com/reference/androidx/activity/ComponentActivity), [Toolbar](https://developer.android.com/reference/androidx/appcompat/widget/Toolbar)

|---|---|
| `https://developer.android.com/reference/androidx/activity/ComponentActivity` | Base class for activities that enables composition of higher level components. |
| `https://developer.android.com/reference/androidx/appcompat/widget/Toolbar` | A standard toolbar for use within application content. |

Known indirect subclasses [AppCompatActivity](https://developer.android.com/reference/androidx/appcompat/app/AppCompatActivity), [BaseCarAppActivity](https://developer.android.com/reference/androidx/car/app/activity/BaseCarAppActivity), [CarAppActivity](https://developer.android.com/reference/androidx/car/app/activity/CarAppActivity), [FragmentActivity](https://developer.android.com/reference/androidx/fragment/app/FragmentActivity), [LauncherActivity](https://developer.android.com/reference/androidx/car/app/activity/LauncherActivity)

|---|---|
| `https://developer.android.com/reference/androidx/appcompat/app/AppCompatActivity` | Base class for activities that wish to use some of the newer platform features on older Android devices. |
| `https://developer.android.com/reference/androidx/car/app/activity/BaseCarAppActivity` | Core logic for CarAppLibrary Activity interaction with a host. |
| `https://developer.android.com/reference/androidx/car/app/activity/CarAppActivity` | The class representing a car app activity in the main display. |
| `https://developer.android.com/reference/androidx/fragment/app/FragmentActivity` | Base class for activities that want to use the support-based `https://developer.android.com/reference/androidx/fragment/app/Fragment`. |
| `https://developer.android.com/reference/androidx/car/app/activity/LauncherActivity` | This class handles providing the right launcher activity when running native applications and Car App Library applications. |

*** ** * ** ***

A class that allows you to host and keep track of `https://developer.android.com/reference/androidx/core/view/MenuProvider`s that will supply `https://developer.android.com/reference/android/view/MenuItem.html`s to the app bar.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/core/view/MenuHostHelper` |   |

## Summary

| ### Public methods |
|---|---|
| `abstract void` | `https://developer.android.com/reference/androidx/core/view/MenuHost#addMenuProvider(androidx.core.view.MenuProvider)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/core/view/MenuProvider provider)` Adds the given `https://developer.android.com/reference/androidx/core/view/MenuProvider` to this `https://developer.android.com/reference/androidx/core/view/MenuHost`. |
| `abstract void` | `https://developer.android.com/reference/androidx/core/view/MenuHost#addMenuProvider(androidx.core.view.MenuProvider,androidx.lifecycle.LifecycleOwner)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/core/view/MenuProvider provider, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/lifecycle/LifecycleOwner owner )` Adds the given `https://developer.android.com/reference/androidx/core/view/MenuProvider` to this `https://developer.android.com/reference/androidx/core/view/MenuHost`. |
| `abstract void` | `https://developer.android.com/reference/androidx/core/view/MenuHost#addMenuProvider(androidx.core.view.MenuProvider,androidx.lifecycle.LifecycleOwner,androidx.lifecycle.Lifecycle.State)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/core/view/MenuProvider provider, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/lifecycle/LifecycleOwner owner, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/lifecycle/Lifecycle.State state )` Adds the given `https://developer.android.com/reference/androidx/core/view/MenuProvider` to this `https://developer.android.com/reference/androidx/core/view/MenuHost` once the given `https://developer.android.com/reference/androidx/lifecycle/LifecycleOwner` reaches the given `https://developer.android.com/reference/androidx/lifecycle/Lifecycle.State`. |
| `abstract void` | `https://developer.android.com/reference/androidx/core/view/MenuHost#invalidateMenu()()` Invalidates the `https://developer.android.com/reference/android/view/Menu.html` to ensure that what is displayed matches the current internal state of the menu. |
| `abstract void` | `https://developer.android.com/reference/androidx/core/view/MenuHost#removeMenuProvider(androidx.core.view.MenuProvider)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/core/view/MenuProvider provider)` Removes the given `https://developer.android.com/reference/androidx/core/view/MenuProvider` from this `https://developer.android.com/reference/androidx/core/view/MenuHost`. |

## Public methods

### addMenuProvider

Added in [1.7.0](https://developer.android.com/jetpack/androidx/releases/core#1.7.0)

```
abstract void addMenuProvider(@NonNull MenuProvider provider)
```

Adds the given `https://developer.android.com/reference/androidx/core/view/MenuProvider` to this `https://developer.android.com/reference/androidx/core/view/MenuHost`. If using this method, you must manually remove the provider when necessary.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/core/view/MenuProvider provider` | the MenuProvider to be added |

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/core/view/MenuHost#removeMenuProvider(androidx.core.view.MenuProvider)` |   |

### addMenuProvider

Added in [1.7.0](https://developer.android.com/jetpack/androidx/releases/core#1.7.0)

```
abstract void addMenuProvider(
    @NonNull MenuProvider provider,
    @NonNull LifecycleOwner owner
)
```

Adds the given `https://developer.android.com/reference/androidx/core/view/MenuProvider` to this `https://developer.android.com/reference/androidx/core/view/MenuHost`. This `https://developer.android.com/reference/androidx/core/view/MenuProvider` will be removed once the given `https://developer.android.com/reference/androidx/lifecycle/LifecycleOwner` receives an Lifecycle.Event.ON_DESTROY event.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/core/view/MenuProvider provider` | the MenuProvider to be added |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/lifecycle/LifecycleOwner owner` | the Lifecycle owner whose state will determine the removal of the provider |

### addMenuProvider

Added in [1.7.0](https://developer.android.com/jetpack/androidx/releases/core#1.7.0)

```
abstract void addMenuProvider(
    @NonNull MenuProvider provider,
    @NonNull LifecycleOwner owner,
    @NonNull Lifecycle.State state
)
```

Adds the given `https://developer.android.com/reference/androidx/core/view/MenuProvider` to this `https://developer.android.com/reference/androidx/core/view/MenuHost` once the given `https://developer.android.com/reference/androidx/lifecycle/LifecycleOwner` reaches the given `https://developer.android.com/reference/androidx/lifecycle/Lifecycle.State`. This `https://developer.android.com/reference/androidx/core/view/MenuProvider` will be removed once the given `https://developer.android.com/reference/androidx/lifecycle/LifecycleOwner` goes down from the given `https://developer.android.com/reference/androidx/lifecycle/Lifecycle.State`.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/core/view/MenuProvider provider` | the MenuProvider to be added |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/lifecycle/LifecycleOwner owner` | the Lifecycle owner whose state will be used for automated addition/removal |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/lifecycle/Lifecycle.State state` | the Lifecycle.State to check for automated addition/removal |

### invalidateMenu

Added in [1.7.0](https://developer.android.com/jetpack/androidx/releases/core#1.7.0)

```
abstract void invalidateMenu()
```

Invalidates the `https://developer.android.com/reference/android/view/Menu.html` to ensure that what is displayed matches the current internal state of the menu. This should be called whenever the state of the menu is changed, such as items being removed or disabled based on some user event.

### removeMenuProvider

Added in [1.7.0](https://developer.android.com/jetpack/androidx/releases/core#1.7.0)

```
abstract void removeMenuProvider(@NonNull MenuProvider provider)
```

Removes the given `https://developer.android.com/reference/androidx/core/view/MenuProvider` from this `https://developer.android.com/reference/androidx/core/view/MenuHost`.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/core/view/MenuProvider provider` | the MenuProvider to be removed |