LifecycleOwner


Known direct subclasses
ActivityHolder

A holder for the Activity created for SDK.

ComponentActivity

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

ComponentDialog

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

Fragment

Static library support version of the framework's android.app.Fragment.

LifecycleRegistryOwner

This interface is deprecated.

Use androidx.appcompat.app.AppCompatActivity which extends LifecycleOwner, so there are no use cases for this class.

LifecycleResumePauseEffectScope

Receiver scope for LifecycleResumeEffect that offers the onPauseOrDispose clause to couple the ON_RESUME effect.

LifecycleService

A Service that is also a LifecycleOwner.

LifecycleStartStopEffectScope

Receiver scope for LifecycleStartEffect that offers the onStopOrDispose clause to couple the ON_START effect.

NavBackStackEntry

Representation of an entry in the back stack of a androidx.navigation.NavController.

OnBackPressedDispatcherOwner

A class that has an OnBackPressedDispatcher that allows you to register a OnBackPressedCallback for handling the system back button.

ProcessLifecycleOwner

Class that provides lifecycle for the whole application process.

SavedStateRegistryOwner

A scope that owns SavedStateRegistry

Screen

A Screen has a Lifecycle and provides the mechanism for the app to send Templates to display when the Screen is visible.

Session

The base class for implementing a session for a car app.

TestLifecycleOwner

Create a LifecycleOwner that allows changing the state via the handleLifecycleEvent method or currentState property.

Known indirect subclasses
AbstractListDetailFragment

A fragment supports adaptive two-pane layout.

AbstractProgressFragment

The base class for Fragments that handle dynamic feature installation.

AlertDialog

A subclass of Dialog that can display one, two or three buttons.

AmbientModeSupport

This class is deprecated.

Use AmbientLifecycleObserver instead.

AppCompatActivity

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

AppCompatDialogFragment

A special version of DialogFragment which uses an AppCompatDialog in place of a platform-styled dialog.

AppCompatDialog

Base class for AppCompat themed android.app.Dialogs.

BaseCarAppActivity

Core logic for CarAppLibrary Activity interaction with a host.

BaseLeanbackPreferenceFragmentCompat

This fragment provides a preference fragment with leanback-style behavior, suitable for embedding into broader UI elements.

BaseSupportFragment

Base class for leanback Fragments.

BrandedSupportFragment

Fragment class for managing search and branding using a view that implements TitleViewAdapter.Provider.

BrowseSupportFragment

A fragment for creating Leanback browse screens.

CarAppActivity

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

ComponentActivity

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

ComponentDialog

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

ComposableFragment

This class provides a Fragment wrapper around a composable function that is loaded via reflection.

ComposableNavHostFragment

A NavHostFragment that adds support for ComposableFragment instances via ComposableFragmentNavigator.

DefaultProgressFragment

The default androidx.fragment.app.Fragment to display during installation progress.

DetailsSupportFragment

A fragment for creating Leanback details screens.

DialogFragment

A fragment that displays a dialog window, floating in the foreground of its activity's window.

DynamicNavHostFragment

The NavHostFragment for dynamic features.

EditTextPreferenceDialogFragmentCompat
ErrorSupportFragment

A fragment for displaying an error indication.

FragmentActivity

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

Fragment

Static library support version of the framework's android.app.Fragment.

GuidedStepSupportFragment

A GuidedStepSupportFragment is used to guide the user through a decision or series of decisions.

HeadersSupportFragment

An fragment containing a list of row headers.

LauncherActivity

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

LeanbackEditTextPreferenceDialogFragmentCompat

Implemented a dialog to input text.

LeanbackListPreferenceDialogFragmentCompat

Implemented a dialog to show ListPreference or MultiSelectListPreference.

LeanbackPreferenceDialogFragmentCompat

A fragment that shows DialogPreference, for example or androidx.preference.MultiSelectListPreference.

LeanbackPreferenceFragmentCompat

This fragment provides a fully decorated leanback-style preference fragment, including a list background and header.

LeanbackSettingsFragmentCompat

This fragment provides a container for displaying a LeanbackPreferenceFragmentCompat

ListFragment

Static library support version of the framework's android.app.ListFragment.

ListPreferenceDialogFragmentCompat
MediaRouteChooserDialogFragment

Media route chooser dialog fragment.

MediaRouteChooserDialog

This class implements the route chooser dialog for MediaRouter.

MediaRouteControllerDialogFragment

Media route controller dialog fragment.

MediaRouteControllerDialog

This class implements the route controller dialog for MediaRouter.

MediaRouteDiscoveryFragment

Media route discovery fragment.

MultiSelectListPreferenceDialogFragmentCompat
NavBackStackEntry

Representation of an entry in the back stack of a androidx.navigation.NavController.

NavHostFragment

NavHostFragment provides an area within your layout for self-contained navigation to occur.

OnboardingSupportFragment

An OnboardingSupportFragment provides a common and simple way to build onboarding screen for applications.

PdfViewerFragment

A Fragment that renders a PDF document.

PlaybackSupportFragment

A fragment for displaying playback controls and related content.

PreferenceDialogFragmentCompat

Abstract base class which presents a dialog associated with a DialogPreference.

PreferenceFragmentCompat

A PreferenceFragmentCompat is the entry point to using the Preference library.

PreferenceHeaderFragmentCompat

PreferenceHeaderFragmentCompat implements a two-pane fragment for preferences.

PreviewActivity

Activity used to run @Composable previews from Android Studio.

RowsSupportFragment

An ordered set of rows of leanback widgets.

SdkActivity

Activity to start for SDKs running locally.

SearchSupportFragment

A fragment to handle searches.

SubspaceTestingActivity

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

VerticalGridSupportFragment

A fragment for creating leanback vertical grids.

VideoSupportFragment

Subclass of PlaybackSupportFragment that is responsible for providing a SurfaceView and rendering video.


A class that has an Android lifecycle. These events can be used by custom components to handle lifecycle changes without implementing any code inside the Activity or the Fragment.

Summary

Public properties

Lifecycle

Returns the Lifecycle of the provider.

Cmn

Extension functions

suspend T
<T : Any?> LifecycleOwner.whenCreated(block: suspend CoroutineScope.() -> T)

This function is deprecated. whenCreated has been deprecated because it runs the block on a pausing dispatcher that suspends, rather than cancels work when the lifecycle state goes below the given state.

android
suspend T
<T : Any?> LifecycleOwner.whenResumed(block: suspend CoroutineScope.() -> T)

This function is deprecated. whenResumed has been deprecated because it runs the block on a pausing dispatcher that suspends, rather than cancels work when the lifecycle state goes below the given state.

android
suspend T
<T : Any?> LifecycleOwner.whenStarted(block: suspend CoroutineScope.() -> T)

This function is deprecated. whenStarted has been deprecated because it runs the block on a pausing dispatcher that suspends, rather than cancels work when the lifecycle state goes below the given state.

android
suspend Unit
LifecycleOwner.repeatOnLifecycle(
    state: Lifecycle.State,
    block: suspend CoroutineScope.() -> Unit
)

LifecycleOwner's extension function for Lifecycle.repeatOnLifecycle to allow an easier call to the API from LifecycleOwners such as Activities and Fragments.

Cmn
suspend inline R
<R : Any?> LifecycleOwner.withCreated(crossinline block: () -> R)

Run block with this LifecycleOwner's Lifecycle in a Lifecycle.State of at least Lifecycle.State.CREATED and resume with the result.

Cmn
suspend inline R
<R : Any?> LifecycleOwner.withResumed(crossinline block: () -> R)

Run block with this LifecycleOwner's Lifecycle in a Lifecycle.State of at least Lifecycle.State.RESUMED and resume with the result.

Cmn
suspend inline R
<R : Any?> LifecycleOwner.withStarted(crossinline block: () -> R)

Run block with this LifecycleOwner's Lifecycle in a Lifecycle.State of at least Lifecycle.State.STARTED and resume with the result.

Cmn
suspend inline R
<R : Any?> LifecycleOwner.withStateAtLeast(
    state: Lifecycle.State,
    crossinline block: () -> R
)

Run block with this LifecycleOwner's Lifecycle in a Lifecycle.State of at least state and resume with the result.

Cmn

Public properties

lifecycle

val lifecycleLifecycle

Returns the Lifecycle of the provider.

Returns
Lifecycle

The lifecycle of the provider.

Extension functions

whenCreated

suspend fun <T : Any?> LifecycleOwner.whenCreated(block: suspend CoroutineScope.() -> T): T

Runs the given block when the LifecycleOwner's Lifecycle is at least in Lifecycle.State.CREATED state.

See also
whenStateAtLeast

for details

whenResumed

suspend fun <T : Any?> LifecycleOwner.whenResumed(block: suspend CoroutineScope.() -> T): T

Runs the given block when the LifecycleOwner's Lifecycle is at least in Lifecycle.State.RESUMED state.

See also
whenStateAtLeast

for details

whenStarted

suspend fun <T : Any?> LifecycleOwner.whenStarted(block: suspend CoroutineScope.() -> T): T

Runs the given block when the LifecycleOwner's Lifecycle is at least in Lifecycle.State.STARTED state.

See also
whenStateAtLeast

for details

repeatOnLifecycle

suspend fun LifecycleOwner.repeatOnLifecycle(
    state: Lifecycle.State,
    block: suspend CoroutineScope.() -> Unit
): Unit

LifecycleOwner's extension function for Lifecycle.repeatOnLifecycle to allow an easier call to the API from LifecycleOwners such as Activities and Fragments.

class MyActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
/* ... */
// Runs the block of code in a coroutine when the lifecycle is at least STARTED.
// The coroutine will be cancelled when the ON_STOP event happens and will
// restart executing if the lifecycle receives the ON_START event again.
lifecycleScope.launch {
repeatOnLifecycle(Lifecycle.State.STARTED) {
uiStateFlow.collect { uiState ->
updateUi(uiState)
}
}
}
}
}
suspend inline fun <R : Any?> LifecycleOwner.withCreated(crossinline block: () -> R): R

Run block with this LifecycleOwner's Lifecycle in a Lifecycle.State of at least Lifecycle.State.CREATED and resume with the result. Throws the CancellationException if the lifecycle has reached Lifecycle.State.DESTROYED by the time of the call or before block is able to run.

suspend inline fun <R : Any?> LifecycleOwner.withResumed(crossinline block: () -> R): R

Run block with this LifecycleOwner's Lifecycle in a Lifecycle.State of at least Lifecycle.State.RESUMED and resume with the result. Throws the CancellationException if the lifecycle has reached Lifecycle.State.DESTROYED by the time of the call or before block is able to run.

suspend inline fun <R : Any?> LifecycleOwner.withStarted(crossinline block: () -> R): R

Run block with this LifecycleOwner's Lifecycle in a Lifecycle.State of at least Lifecycle.State.STARTED and resume with the result. Throws the CancellationException if the lifecycle has reached Lifecycle.State.DESTROYED by the time of the call or before block is able to run.

withStateAtLeast

suspend inline fun <R : Any?> LifecycleOwner.withStateAtLeast(
    state: Lifecycle.State,
    crossinline block: () -> R
): R

Run block with this LifecycleOwner's Lifecycle in a Lifecycle.State of at least state and resume with the result. Throws the CancellationException if the lifecycle has reached Lifecycle.State.DESTROYED by the time of the call or before block is able to run.

Extension properties

lifecycleScope

val LifecycleOwner.lifecycleScopeLifecycleCoroutineScope

CoroutineScope tied to this LifecycleOwner's Lifecycle.

This scope will be cancelled when the Lifecycle is destroyed.

This scope is bound to Dispatchers.Main.immediate.