public class RxLifecycle extends Object
| Modifier and Type | Method and Description |
|---|---|
static <T,R> LifecycleTransformer<T> |
bind(Observable<R> lifecycle)
Binds the given source to a lifecycle.
|
static <T,R> LifecycleTransformer<T> |
bind(Observable<R> lifecycle,
Func1<R,R> correspondingEvents)
Binds the given source to a lifecycle.
|
static <T> LifecycleTransformer<T> |
bindActivity(Observable<ActivityEvent> lifecycle)
Binds the given source to an Activity lifecycle.
|
static <T> LifecycleTransformer<T> |
bindFragment(Observable<FragmentEvent> lifecycle)
Binds the given source to a Fragment lifecycle.
|
static <T> LifecycleTransformer<T> |
bindUntilActivityEvent(Observable<ActivityEvent> lifecycle,
ActivityEvent event)
Deprecated.
|
static <T,R> LifecycleTransformer<T> |
bindUntilEvent(Observable<R> lifecycle,
R event)
Binds the given source to a lifecycle.
|
static <T> LifecycleTransformer<T> |
bindUntilFragmentEvent(Observable<FragmentEvent> lifecycle,
FragmentEvent event)
Deprecated.
|
static <T,E> LifecycleTransformer<T> |
bindView(Observable<? extends E> lifecycle)
Deprecated.
|
static <T> LifecycleTransformer<T> |
bindView(View view)
Binds the given source to a View lifecycle.
|
@Deprecated @NonNull @CheckResult public static <T> LifecycleTransformer<T> bindUntilFragmentEvent(@NonNull Observable<FragmentEvent> lifecycle, @NonNull FragmentEvent event)
bindUntilEvent(Observable, Object) instead, which does exactly the same thing.@Deprecated @NonNull @CheckResult public static <T> LifecycleTransformer<T> bindUntilActivityEvent(@NonNull Observable<ActivityEvent> lifecycle, @NonNull ActivityEvent event)
bindUntilEvent(Observable, Object) instead, which does exactly the same thing.@NonNull @CheckResult public static <T,R> LifecycleTransformer<T> bindUntilEvent(@NonNull Observable<R> lifecycle, @NonNull R event)
When the lifecycle event occurs, the source will cease to emit any notifications.
Use with Observable.compose(Observable.Transformer):
source.compose(RxLifecycle.bindUntilEvent(lifecycle, ActivityEvent.STOP)).subscribe()
lifecycle - the lifecycle sequenceevent - the event which should conclude notifications from the sourceObservable.Transformer that unsubscribes the source at the specified event@NonNull @CheckResult public static <T> LifecycleTransformer<T> bindActivity(@NonNull Observable<ActivityEvent> lifecycle)
Use with Observable.compose(Observable.Transformer):
source.compose(RxLifecycle.bindActivity(lifecycle)).subscribe()
This helper automatically determines (based on the lifecycle sequence itself) when the source should stop emitting items. In the case that the lifecycle sequence is in the creation phase (CREATE, START, etc) it will choose the equivalent destructive phase (DESTROY, STOP, etc). If used in the destructive phase, the notifications will cease at the next event; for example, if used in PAUSE, it will unsubscribe in STOP.
Due to the differences between the Activity and Fragment lifecycles, this method should only be used for an Activity lifecycle.
lifecycle - the lifecycle sequence of an Activity
* @return a reusable Observable.Transformer that unsubscribes the source during the Activity lifecycle@NonNull @CheckResult public static <T> LifecycleTransformer<T> bindFragment(@NonNull Observable<FragmentEvent> lifecycle)
Use with Observable.compose(Observable.Transformer):
source.compose(RxLifecycle.bindFragment(lifecycle)).subscribe()
This helper automatically determines (based on the lifecycle sequence itself) when the source should stop emitting items. In the case that the lifecycle sequence is in the creation phase (CREATE, START, etc) it will choose the equivalent destructive phase (DESTROY, STOP, etc). If used in the destructive phase, the notifications will cease at the next event; for example, if used in PAUSE, it will unsubscribe in STOP.
Due to the differences between the Activity and Fragment lifecycles, this method should only be used for a Fragment lifecycle.
lifecycle - the lifecycle sequence of a FragmentObservable.Transformer that unsubscribes the source during the Fragment lifecycle@NonNull @CheckResult public static <T> LifecycleTransformer<T> bindView(@NonNull View view)
Specifically, when the View detaches from the window, the sequence will be completed.
Use with Observable.compose(Observable.Transformer):
source.compose(RxLifecycle.bindView(lifecycle)).subscribe()
Warning: you should make sure to use the returned Transformer on the main thread, since we're binding to a View (which only allows binding on the main thread).
view - the view to bind the source sequence toObservable.Transformer that unsubscribes the source during the View lifecycle@Deprecated @NonNull @CheckResult public static <T,E> LifecycleTransformer<T> bindView(@NonNull Observable<? extends E> lifecycle)
bind(Observable) instead, which does exactly the same thing.@NonNull @CheckResult public static <T,R> LifecycleTransformer<T> bind(@NonNull Observable<R> lifecycle)
Use with Observable.compose(Observable.Transformer):
source.compose(RxLifecycle.bind(lifecycle)).subscribe()
This helper automatically determines (based on the lifecycle sequence itself) when the source should stop emitting items. Note that for this method, it assumes any event emitted by the given lifecycle indicates that the lifecycle is over.
lifecycle - the lifecycle sequenceObservable.Transformer that unsubscribes the source whenever the lifecycle emits@NonNull @CheckResult public static <T,R> LifecycleTransformer<T> bind(@NonNull Observable<R> lifecycle, @NonNull Func1<R,R> correspondingEvents)
This method determines (based on the lifecycle sequence itself) when the source should stop emitting items. It uses the provided correspondingEvents function to determine when to unsubscribe.
Note that this is an advanced usage of the library and should generally be used only if you really know what you're doing with a given lifecycle.
lifecycle - the lifecycle sequencecorrespondingEvents - a function which tells the source when to unsubscribeObservable.Transformer that unsubscribes the source during the Fragment lifecycle