LiveData is a data holder class that can be observed within a given lifecycle.
This means that an
Observer can be added in a pair with a
this observer will be notified about modifications of the wrapped data only if the paired
LifecycleOwner is in active state. LifecycleOwner is considered as active, if its state is
Lifecycle.State.RESUMED. An observer added via
observeForever(Observer) is considered as always active and thus will be always notified
about modifications. For those observers, you should manually call
An observer added with a Lifecycle will be automatically removed if the corresponding
Lifecycle moves to
Lifecycle.State.DESTROYED state. This is especially useful for
activities and fragments where they can safely observe LiveData and not worry about leaks:
they will be instantly unsubscribed when they are destroyed.
In addition, LiveData has
to get notified when number of active
Observers change between 0 and 1.
This allows LiveData to release any heavy resources when it does not have any Observers that
are actively observing.
This class is designed to hold individual data fields of
but can also be used for sharing data between different modules in your application
in a decoupled fashion.
Creates a LiveData initialized with the given
Creates a LiveData with no value assigned to it.
Returns the current value.