Rx - 如何在收到 onNext() 后自动退订?
Rx - How to unsubscribe automatically after receiving onNext()?
如何在收到onNext()后自动退订?
现在我使用这个代码:
rxObservable
.compose(bindToLifecycle()) // unsubscribe automatically in onPause() if method was called in onResume()
.subscribe(new Subscriber<Object>() {
...
@Override
public void onNext(Object o) {
unsubscribe();
}
});
我想"unsubscribe"刚过第一个事件,运算符take
是个办法。
rxObservable.compose(bindToLifecycle())
.take(1)
.subscribe();
我想这就是你需要的:
rxObservable.compose(bindToLifecycle())
.takeFirst(lifecycleEvent -> lifecycleEvent == LifecycleEvent.PAUSE);
如何在收到onNext()后自动退订?
现在我使用这个代码:
rxObservable
.compose(bindToLifecycle()) // unsubscribe automatically in onPause() if method was called in onResume()
.subscribe(new Subscriber<Object>() {
...
@Override
public void onNext(Object o) {
unsubscribe();
}
});
我想"unsubscribe"刚过第一个事件,运算符take
是个办法。
rxObservable.compose(bindToLifecycle())
.take(1)
.subscribe();
我想这就是你需要的:
rxObservable.compose(bindToLifecycle())
.takeFirst(lifecycleEvent -> lifecycleEvent == LifecycleEvent.PAUSE);