observedValue

val <T> LiveData<T>.observedValue: T?

Same as LiveData.getValue, except this variant throws a IllegalStateException when the LiveData instance does not have an active observer.

The returned value is null when the LiveData instance does not have a value yet.

Use this extension property over LiveData.getValue if you need a value of an observed LiveData instance in an observer callback and using the value given to the observer callback is not practical. For example:

source1.observe(this) {
checkFoo()
}

source2.observe(this) {
checkFoo()
}

fun checkFoo() {
if (source1.observedValue?.get(source2.observedValue)) {
...
}
}