belongs to Maven artifact android.arch.lifecycle:reactivestreams:1.1.1
LiveDataReactiveStreams
public
final
class
LiveDataReactiveStreams
extends Object
java.lang.Object | |
↳ | android.arch.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 |
static
<T>
Publisher<T>
|
toPublisher(LifecycleOwner lifecycle, LiveData<T> liveData)
Adapts the given |
Inherited methods | |
---|---|
Public methods
fromPublisher
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
Publisher<T> toPublisher (LifecycleOwner lifecycle, LiveData<T> liveData)
Adapts the given LiveData
stream to a ReactiveStreams Publisher
.
By using a good publisher implementation such as RxJava 2.x Flowables, most consumers will
be able to let the library deal with backpressure using operators and not need to worry about
ever manually calling request(long)
.
On subscription to the publisher, the observer will attach to the given LiveData
.
Once {@link Subscription#request) is called on the subscription object, an observer will be
connected to the data stream. Calling request(Long.MAX_VALUE) is equivalent to creating an
unbounded stream with no backpressure. If request with a finite count reaches 0, the observer
will buffer the latest item and emit it to the subscriber when data is again requested. Any
other items emitted during the time there was no backpressure requested will be dropped.
Parameters | |
---|---|
lifecycle |
LifecycleOwner |
liveData |
LiveData |
Returns | |
---|---|
Publisher<T> |
Annotations
Interfaces
Classes
- AndroidViewModel
- Lifecycle
- LifecycleRegistry
- LifecycleService
- LiveData
- LiveDataReactiveStreams
- MediatorLiveData
- MutableLiveData
- ProcessLifecycleOwner
- ServiceLifecycleDispatcher
- Transformations
- ViewModel
- ViewModelProvider
- ViewModelProvider.AndroidViewModelFactory
- ViewModelProvider.NewInstanceFactory
- ViewModelProviders
- ViewModelProviders.DefaultFactory
- ViewModelStore
- ViewModelStores
Enums