MenuHost

Added in 1.7.0

interface MenuHost

Known direct subclasses
ComponentActivity

Base class for activities that enables composition of higher level components.

Toolbar

A standard toolbar for use within application content.

Known indirect subclasses
AppCompatActivity

Base class for activities that wish to use some of the newer platform features on older Android devices.

BaseCarAppActivity

Core logic for CarAppLibrary Activity interaction with a host.

CarAppActivity

The class representing a car app activity in the main display.

FragmentActivity

Base class for activities that want to use the support-based Fragments.

LauncherActivity

This class handles providing the right launcher activity when running native applications and Car App Library applications.

PreviewActivity

Activity used to run @Composable previews from Android Studio.

SdkActivity

Activity to start for SDKs running locally.

SubspaceTestingActivity

Custom test class that should be used for testing SubspaceComposable content.


A class that allows you to host and keep track of MenuProviders that will supply android.view.MenuItems to the app bar.

See also
MenuHostHelper

Summary

Public functions

Unit

Adds the given MenuProvider to this MenuHost.

Unit

Adds the given MenuProvider to this MenuHost.

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

Adds the given MenuProvider to this MenuHost once the given LifecycleOwner reaches the given Lifecycle.State.

Unit

Invalidates the android.view.Menu to ensure that what is displayed matches the current internal state of the menu.

Unit

Removes the given MenuProvider from this MenuHost.

Public functions

addMenuProvider

Added in 1.7.0
fun addMenuProvider(provider: MenuProvider): Unit

Adds the given MenuProvider to this MenuHost. If using this method, you must manually remove the provider when necessary.

Parameters
provider: MenuProvider

the MenuProvider to be added

addMenuProvider

Added in 1.7.0
fun addMenuProvider(provider: MenuProvider, owner: LifecycleOwner): Unit

Adds the given MenuProvider to this MenuHost. This MenuProvider will be removed once the given LifecycleOwner receives an 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

addMenuProvider

Added in 1.7.0
fun addMenuProvider(
    provider: MenuProvider,
    owner: LifecycleOwner,
    state: Lifecycle.State
): Unit

Adds the given MenuProvider to this MenuHost 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.

Parameters
provider: MenuProvider

the MenuProvider to be added

owner: LifecycleOwner

the Lifecycle owner whose state will be used for automated addition/removal

state: Lifecycle.State

the Lifecycle.State to check for automated addition/removal

invalidateMenu

Added in 1.7.0
fun invalidateMenu(): Unit

Invalidates the android.view.Menu 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
fun removeMenuProvider(provider: MenuProvider): Unit

Removes the given MenuProvider from this MenuHost.

Parameters
provider: MenuProvider

the MenuProvider to be removed