# LiveDataKt

Added in 2.8.0

*** ** * ** ***


```
public final class LiveDataKt
```

<br />

*** ** * ** ***

## Summary

| ### Public methods |
|---|---|
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/lifecycle/Observer<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | `@https://developer.android.com/reference/androidx/annotation/MainThread <T extends https://developer.android.com/reference/java/lang/Object.html> [observe](https://developer.android.com/reference/androidx/lifecycle/LiveDataKt#(androidx.lifecycle.LiveData).observe(androidx.lifecycle.LifecycleOwner,kotlin.Function1))( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/lifecycle/LiveData<@https://developer.android.com/reference/androidx/annotation/NonNull T> receiver, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/lifecycle/LifecycleOwner owner, @https://developer.android.com/reference/androidx/annotation/NonNull Function1<@https://developer.android.com/reference/androidx/annotation/NonNull T, https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html> onChanged )` **This method is deprecated.** This extension method is not required when using Kotlin 1.4. |

## Public methods

### observe

Artifact: [androidx.lifecycle:lifecycle-livedata-core](https://developer.android.com/jetpack/androidx/releases/lifecycle) [View Source](https://cs.android.com/search?q=file:androidx/lifecycle/LiveData.kt+function:observe) Added in [2.8.0](https://developer.android.com/jetpack/androidx/releases/lifecycle#2.8.0) Deprecated in [2.8.0](https://developer.android.com/jetpack/androidx/releases/lifecycle#2.8.0)

```
@MainThread
public static final @NonNull Observer<@NonNull T> <T extends Object> [observe](https://developer.android.com/reference/androidx/lifecycle/LiveDataKt#(androidx.lifecycle.LiveData).observe(androidx.lifecycle.LifecycleOwner,kotlin.Function1))(
    @NonNull LiveData<@NonNull T> receiver,
    @NonNull LifecycleOwner owner,
    @NonNull Function1<@NonNull T, Unit> onChanged
)
```

> [!CAUTION]
> **This method is deprecated.**   
> This extension method is not required when using Kotlin 1.4. You should remove "import androidx.lifecycle.observe"

Adds the given `https://developer.android.com/reference/androidx/lifecycle/package-summary#(androidx.lifecycle.LiveData).observe(androidx.lifecycle.LifecycleOwner,kotlin.Function1)` lambda as an observer within the lifespan of the given `https://developer.android.com/reference/androidx/lifecycle/package-summary#(androidx.lifecycle.LiveData).observe(androidx.lifecycle.LifecycleOwner,kotlin.Function1)` and returns a reference to observer. The events are dispatched on the main thread. If LiveData already has data set, it will be delivered to the onChanged.

The observer will only receive events if the owner is in `https://developer.android.com/reference/androidx/lifecycle/Lifecycle.State#STARTED` or `https://developer.android.com/reference/androidx/lifecycle/Lifecycle.State#RESUMED` state (active).

If the owner moves to the `https://developer.android.com/reference/androidx/lifecycle/Lifecycle.State#DESTROYED` state, the observer will automatically be removed.

When data changes while the `https://developer.android.com/reference/androidx/lifecycle/package-summary#(androidx.lifecycle.LiveData).observe(androidx.lifecycle.LifecycleOwner,kotlin.Function1)` is not active, it will not receive any updates. If it becomes active again, it will receive the last available data automatically.

LiveData keeps a strong reference to the observer and the owner as long as the given LifecycleOwner is not destroyed. When it is destroyed, LiveData removes references to the observer and the owner.

If the given owner is already in `https://developer.android.com/reference/androidx/lifecycle/Lifecycle.State#DESTROYED` state, LiveData ignores the call.