public class RxLifecycle extends Object
| Modifier and Type | Method and Description |
|---|---|
static <T> Observable.Transformer<? super T,? extends T> |
bindActivity(Observable<ActivityEvent> lifecycle)
Binds the given source to an Activity lifecycle.
|
static <T> Observable.Transformer<? super T,? extends T> |
bindFragment(Observable<FragmentEvent> lifecycle)
Binds the given source to a Fragment lifecycle.
|
static <T> Observable.Transformer<? super T,? extends T> |
bindUntilActivityEvent(Observable<ActivityEvent> lifecycle,
ActivityEvent event)
Binds the given source to an Activity lifecycle.
|
static <T> Observable.Transformer<? super T,? extends T> |
bindUntilFragmentEvent(Observable<FragmentEvent> lifecycle,
FragmentEvent event)
Binds the given source to a Fragment lifecycle.
|
static <T,E> Observable.Transformer<? super T,? extends T> |
bindView(Observable<? extends E> lifecycle)
Binds the given source a View lifecycle.
|
static <T> Observable.Transformer<? super T,? extends T> |
bindView(View view)
Binds the given source a View lifecycle.
|
public static <T> Observable.Transformer<? super T,? extends T> bindUntilFragmentEvent(Observable<FragmentEvent> lifecycle, FragmentEvent 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, FragmentEvent.STOP)).subscribe()
lifecycle - the Fragment lifecycle sequenceevent - the event which should conclude notifications from the sourceObservable.Transformer that unsubscribes the source at the specified eventpublic static <T> Observable.Transformer<? super T,? extends T> bindUntilActivityEvent(Observable<ActivityEvent> lifecycle, ActivityEvent 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 Activity lifecycle sequenceevent - the event which should conclude notifications from the sourceObservable.Transformer that unsubscribes the source at the specified eventpublic static <T> Observable.Transformer<? super T,? extends T> bindActivity(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 lifecyclepublic static <T> Observable.Transformer<? super T,? extends T> bindFragment(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 lifecyclepublic static <T> Observable.Transformer<? super T,? extends T> bindView(View view)
Use with Observable.compose(Observable.Transformer):
source.compose(RxLifecycle.bindView(lifecycle)).subscribe()
This helper automatically determines (based on the lifecycle sequence itself) when the source should stop emitting items. For views, this effectively means watching for a detach event and unsubscribing the sequence when one occurs.
Note that this will unsubscribe after the first ViewAttachEvent.Kind#DETACH event is received,
and will not resume if the view is re-attached later.
view - the view to bind the source sequence toObservable.Transformer that unsubscribes the source during the View lifecyclepublic static <T,E> Observable.Transformer<? super T,? extends T> bindView(Observable<? extends E> lifecycle)
Use with Observable.compose(Observable.Transformer):
source.compose(RxLifecycle.bindView(lifecycle)).subscribe()
This helper automatically determines (based on the lifecycle sequence itself) when the source should stop emitting items. For views, this effectively means watching for a detach event and unsubscribing the sequence when one occurs. Note that this assumes any event emitted by the given lifecycle indicates a detach event.
lifecycle - the lifecycle sequence of a ViewObservable.Transformer that unsubscribes the source during the View lifecycle