Stay organized with collections
Save and categorize content based on your preferences.
added in
version 1.1.0
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
Inherited methods |
From class
java.lang.Object
Object
|
clone()
|
boolean
|
equals(Object arg0)
|
void
|
finalize()
|
final
Class<?>
|
getClass()
|
int
|
hashCode()
|
final
void
|
notify()
|
final
void
|
notifyAll()
|
String
|
toString()
|
final
void
|
wait(long arg0, int arg1)
|
final
void
|
wait(long arg0)
|
final
void
|
wait()
|
|
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 |
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 |
Annotations
Interfaces
Classes
Enums
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-02-10 UTC.
[null,null,["Last updated 2025-02-10 UTC."],[],[],null,["# LiveDataReactiveStreams\n\nadded in [version 1.1.0](/topic/libraries/support-library/revisions) \nbelongs to Maven artifact android.arch.lifecycle:reactivestreams:1.1.1 \nSummary: [Methods](#pubmethods) \\| [Inherited Methods](#inhmethods) \n\nLiveDataReactiveStreams\n=======================\n\n| The `android.arch` Architecture Components packages are no longer maintained. They have been superseded by the corresponding [androidx.\\*](/jetpack/androidx/migrate) packages. See [androidx.lifecycle.LiveDataReactiveStreams](/reference/androidx/lifecycle/LiveDataReactiveStreams) instead.\n\n\n`\npublic\n\nfinal\n\nclass\nLiveDataReactiveStreams\n`\n\n\n`\n\nextends Object\n\n\n`\n\n`\n\n\n`\n\n|---|------------------------------------------------|\n| java.lang.Object ||\n| ↳ | android.arch.lifecycle.LiveDataReactiveStreams |\n\n\u003cbr /\u003e\n\n*** ** * ** ***\n\nAdapts [LiveData](/reference/android/arch/lifecycle/LiveData) input and output to the ReactiveStreams spec.\n\nSummary\n-------\n\n| ### Public methods ||\n|---------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| ` static \u003cT\u003e `[LiveData](/reference/android/arch/lifecycle/LiveData)`\u003cT\u003e` | ` `[fromPublisher](/reference/android/arch/lifecycle/LiveDataReactiveStreams#fromPublisher(org.reactivestreams.Publisher\u003cT\u003e))`(Publisher\u003cT\u003e publisher) ` Creates an Observable [LiveData](/reference/android/arch/lifecycle/LiveData) stream from a ReactiveStreams publisher. |\n| ` static \u003cT\u003e Publisher\u003cT\u003e` | ` `[toPublisher](/reference/android/arch/lifecycle/LiveDataReactiveStreams#toPublisher(android.arch.lifecycle.LifecycleOwner, android.arch.lifecycle.LiveData\u003cT\u003e))`(`[LifecycleOwner](/reference/android/arch/lifecycle/LifecycleOwner)` lifecycle, `[LiveData](/reference/android/arch/lifecycle/LiveData)`\u003cT\u003e liveData) ` Adapts the given [LiveData](/reference/android/arch/lifecycle/LiveData) stream to a ReactiveStreams [Publisher](/reference/org/reactivestreams/Publisher). |\n\n| ### Inherited methods |\n|-----------------------|---|\n| From class ` java.lang.Object ` |-------------------|-------------------------------| | ` Object` | ` clone() ` | | ` boolean` | ` equals(Object arg0) ` | | ` void` | ` finalize() ` | | ` final Class\u003c?\u003e` | ` getClass() ` | | ` int` | ` hashCode() ` | | ` final void` | ` notify() ` | | ` final void` | ` notifyAll() ` | | ` String` | ` toString() ` | | ` final void` | ` wait(long arg0, int arg1) ` | | ` final void` | ` wait(long arg0) ` | | ` final void` | ` wait() ` | ||\n\nPublic methods\n--------------\n\n### fromPublisher\n\nadded in [version 1.1.0](/topic/libraries/support-library/revisions) \n\n```\nLiveData\u003cT\u003e fromPublisher (Publisher\u003cT\u003e publisher)\n```\n\nCreates an Observable [LiveData](/reference/android/arch/lifecycle/LiveData) stream from a ReactiveStreams publisher.\n\n\nWhen the LiveData becomes active, it subscribes to the emissions from the Publisher.\n\n\nWhen the LiveData becomes inactive, the subscription is cleared.\nLiveData holds the last value emitted by the Publisher when the LiveData was active.\n\n\nTherefore, in the case of a hot RxJava Observable, when a new LiveData [Observer](/reference/android/arch/lifecycle/Observer) is\nadded, it will automatically notify with the last value held in LiveData,\nwhich might not be the last value emitted by the Publisher.\n\n\nNote that LiveData does NOT handle errors and it expects that errors are treated as states\nin the data that's held. In case of an error being emitted by the publisher, an error will\nbe propagated to the main thread and the app will crash.\n\n\u003cbr /\u003e\n\n| Parameters ||\n|-------------|--------------------|\n| `publisher` | `Publisher` \u003cbr /\u003e |\n\n| Returns ||\n|-------------------------------------------------------------|--------|\n| [LiveData](/reference/android/arch/lifecycle/LiveData)`\u003cT\u003e` | \u003cbr /\u003e |\n\n### toPublisher\n\nadded in [version 1.1.0](/topic/libraries/support-library/revisions) \n\n```\nPublisher\u003cT\u003e toPublisher (LifecycleOwner lifecycle, \n LiveData\u003cT\u003e liveData)\n```\n\nAdapts the given [LiveData](/reference/android/arch/lifecycle/LiveData) stream to a ReactiveStreams [Publisher](/reference/org/reactivestreams/Publisher).\n\n\nBy using a good publisher implementation such as RxJava 2.x Flowables, most consumers will\nbe able to let the library deal with backpressure using operators and not need to worry about\never manually calling [request(long)](/reference/org/reactivestreams/Subscription#request(long)).\n\n\nOn subscription to the publisher, the observer will attach to the given [LiveData](/reference/android/arch/lifecycle/LiveData).\nOnce {@link Subscription#request) is called on the subscription object, an observer will be\nconnected to the data stream. Calling request(Long.MAX_VALUE) is equivalent to creating an\nunbounded stream with no backpressure. If request with a finite count reaches 0, the observer\nwill buffer the latest item and emit it to the subscriber when data is again requested. Any\nother items emitted during the time there was no backpressure requested will be dropped.\n\n\u003cbr /\u003e\n\n| Parameters ||\n|-------------|-------------------------|\n| `lifecycle` | `LifecycleOwner` \u003cbr /\u003e |\n| `liveData` | `LiveData` \u003cbr /\u003e |\n\n| Returns ||\n|----------------|--------|\n| `Publisher\u003cT\u003e` | \u003cbr /\u003e |\n\n-\n\n Annotations\n -----------\n\n - [OnLifecycleEvent](/reference/android/arch/lifecycle/OnLifecycleEvent)\n-\n\n Interfaces\n ----------\n\n - [DefaultLifecycleObserver](/reference/android/arch/lifecycle/DefaultLifecycleObserver)\n - [LifecycleObserver](/reference/android/arch/lifecycle/LifecycleObserver)\n - [LifecycleOwner](/reference/android/arch/lifecycle/LifecycleOwner)\n - [LifecycleRegistryOwner](/reference/android/arch/lifecycle/LifecycleRegistryOwner)\n - [Observer](/reference/android/arch/lifecycle/Observer)\n - [ViewModelProvider.Factory](/reference/android/arch/lifecycle/ViewModelProvider.Factory)\n - [ViewModelStoreOwner](/reference/android/arch/lifecycle/ViewModelStoreOwner)\n-\n\n Classes\n -------\n\n - [AndroidViewModel](/reference/android/arch/lifecycle/AndroidViewModel)\n - [Lifecycle](/reference/android/arch/lifecycle/Lifecycle)\n - [LifecycleRegistry](/reference/android/arch/lifecycle/LifecycleRegistry)\n - [LifecycleService](/reference/android/arch/lifecycle/LifecycleService)\n - [LiveData](/reference/android/arch/lifecycle/LiveData)\n - [LiveDataReactiveStreams](/reference/android/arch/lifecycle/LiveDataReactiveStreams)\n - [MediatorLiveData](/reference/android/arch/lifecycle/MediatorLiveData)\n - [MutableLiveData](/reference/android/arch/lifecycle/MutableLiveData)\n - [ProcessLifecycleOwner](/reference/android/arch/lifecycle/ProcessLifecycleOwner)\n - [ServiceLifecycleDispatcher](/reference/android/arch/lifecycle/ServiceLifecycleDispatcher)\n - [Transformations](/reference/android/arch/lifecycle/Transformations)\n - [ViewModel](/reference/android/arch/lifecycle/ViewModel)\n - [ViewModelProvider](/reference/android/arch/lifecycle/ViewModelProvider)\n - [ViewModelProvider.AndroidViewModelFactory](/reference/android/arch/lifecycle/ViewModelProvider.AndroidViewModelFactory)\n - [ViewModelProvider.NewInstanceFactory](/reference/android/arch/lifecycle/ViewModelProvider.NewInstanceFactory)\n - [ViewModelProviders](/reference/android/arch/lifecycle/ViewModelProviders)\n - [ViewModelProviders.DefaultFactory](/reference/android/arch/lifecycle/ViewModelProviders.DefaultFactory)\n - [ViewModelStore](/reference/android/arch/lifecycle/ViewModelStore)\n - [ViewModelStores](/reference/android/arch/lifecycle/ViewModelStores)\n-\n\n Enums\n -----\n\n - [Lifecycle.Event](/reference/android/arch/lifecycle/Lifecycle.Event)\n - [Lifecycle.State](/reference/android/arch/lifecycle/Lifecycle.State)"]]