Google은 흑인 공동체를 위한 인종 간 평등을 진전시키기 위해 노력하고 있습니다. Google에서 어떤 노력을 하고 있는지 확인하세요.

LiveDataScope

interface LiveDataScope<T>
androidx.lifecycle.LiveDataScope

Interface that allows controlling a LiveData from a coroutine block.

Summary

Public methods
abstract suspend Unit
emit(value: T)

Set's the LiveData's value to the given value.

abstract suspend DisposableHandle
emitSource(source: LiveData<T>)

Add the given LiveData as a source, similar to MediatorLiveData.addSource.

Properties
abstract T?

References the current value of the LiveData.

Public methods

emit

abstract suspend fun emit(value: T): Unit

Set's the LiveData's value to the given value. If you've called emitSource previously, calling emit will remove that source.

Note that this function suspends until the value is set on the LiveData.

Parameters
value: T The new value for the LiveData

See Also

emitSource

abstract suspend fun emitSource(source: LiveData<T>): DisposableHandle

Add the given LiveData as a source, similar to MediatorLiveData.addSource. Calling this method will remove any source that was yielded before via emitSource.

Parameters
source: LiveData<T> The LiveData instance whose values will be dispatched from the current LiveData.

Properties

latestValue

abstract val latestValue: T?

References the current value of the LiveData.

If the block never emited a value, latestValue will be null. You can use this value to check what was then latest value emited by your block before it got cancelled.

Note that if the block called emitSource, then latestValue will be last value dispatched by the source LiveData.