LiveDataReactiveStreams

public final class LiveDataReactiveStreams
extends Object

java.lang.Object
   ↳ androidx.lifecycle.LiveDataReactiveStreams


Adapts LiveData input and output to the ReactiveStreams spec.

Summary

Public methods

static <T> LiveData<T> fromPublisher(Publisher<T> publisher)

Creates an observable LiveData stream from a ReactiveStreams Publisher}.

static <T> Publisher<T> toPublisher(LifecycleOwner lifecycle, LiveData<T> liveData)

Adapts the given LiveData stream to a ReactiveStreams Publisher.

Inherited methods

Public methods

fromPublisher

public static LiveData<T> fromPublisher (Publisher<T> publisher)

Creates an observable LiveData stream from a ReactiveStreams Publisher}.

When the LiveData becomes active, it subscribes to the emissions from the Publisher.

When the LiveData becomes inactive, the subscription is cleared. LiveData holds the last value emitted by the Publisher when the LiveData was active.

Therefore, in the case of a hot RxJava Observable, when a new LiveData Observer is added, it will automatically notify with the last value held in LiveData, which might not be the last value emitted by the Publisher.

Note that LiveData does NOT handle errors and it expects that errors are treated as states in the data that's held. In case of an error being emitted by the publisher, an error will be propagated to the main thread and the app will crash.

Parameters
publisher Publisher

Returns
LiveData<T>

toPublisher