MenuHost

Added in 1.7.0

public 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.

SdkActivity

Activity to start for SDKs running locally.


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 methods

abstract void

Adds the given MenuProvider to this MenuHost.

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

Adds the given MenuProvider to this MenuHost.

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

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

abstract void

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

abstract void

Removes the given MenuProvider from this MenuHost.

Public methods

addMenuProvider

Added in 1.7.0
abstract void addMenuProvider(@NonNull MenuProvider provider)

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

Parameters
@NonNull MenuProvider provider

the MenuProvider to be added

addMenuProvider

Added in 1.7.0
abstract void addMenuProvider(
    @NonNull MenuProvider provider,
    @NonNull LifecycleOwner owner
)

Adds the given MenuProvider to this MenuHost. This MenuProvider will be removed once the given LifecycleOwner receives an Lifecycle.Event.ON_DESTROY event.

Parameters
@NonNull MenuProvider provider

the MenuProvider to be added

@NonNull LifecycleOwner owner

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

addMenuProvider

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

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
@NonNull MenuProvider provider

the MenuProvider to be added

@NonNull LifecycleOwner owner

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

@NonNull Lifecycle.State state

the Lifecycle.State to check for automated addition/removal

invalidateMenu

Added in 1.7.0
abstract void invalidateMenu()

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
abstract void removeMenuProvider(@NonNull MenuProvider provider)

Removes the given MenuProvider from this MenuHost.

Parameters
@NonNull MenuProvider provider

the MenuProvider to be removed