{% setvar book_path %}/reference/kotlin/androidx/_book.yaml{% endsetvar %} {% include "_shared/_reference-head-tags.html" %}

TestLifecycleOwner

class TestLifecycleOwner : LifecycleOwner


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

Under the hood, this uses a LifecycleRegistry. However, it uses Dispatchers.Main.immediate as the default coroutineDispatcher to ensure that all mutations to the current state are run on that dispatcher, no matter what thread you mutate the state from.

Summary

Public constructors

TestLifecycleOwner(
    initialState: Lifecycle.State,
    coroutineDispatcher: CoroutineDispatcher
)

Public functions

Unit

Update the currentState by moving it to the state directly after the given event.

Public properties

Lifecycle.State

The current Lifecycle.State of this owner.

open LifecycleRegistry

Returns the Lifecycle of the provider.

Int

Get the number of observers.

Public constructors

TestLifecycleOwner

TestLifecycleOwner(
    initialState: Lifecycle.State = Lifecycle.State.STARTED,
    coroutineDispatcher: CoroutineDispatcher = Dispatchers.Main.immediate
)
Parameters
initialState: Lifecycle.State = Lifecycle.State.STARTED

The initial Lifecycle.State.

Public functions

handleLifecycleEvent

fun handleLifecycleEvent(event: Lifecycle.Event): Unit

Update the currentState by moving it to the state directly after the given event. This is safe to call on any thread.

Public properties

currentState

var currentStateLifecycle.State

The current Lifecycle.State of this owner. This is safe to mutate on any thread.

lifecycle

open val lifecycleLifecycleRegistry

Returns the Lifecycle of the provider.

Returns
LifecycleRegistry

The lifecycle of the provider.

observerCount

val observerCountInt

Get the number of observers.