How To Subscribe To Click Events So Exceptions Don't Unsubscribe?
I'm using RxJava for Android (RxAndroid) and I subscribe to click events of a view, and do something on them as follows: subscription = ViewObservable.clicks(view, false) .map(
Solution 1:
Use retry
method:
subscription = ViewObservable.clicks(view, false)
.map(...)
.retry()
.subscribe(subscriberA)
However, you will not receive any exception in onError
.
To handle exceptions with retry (resubscribe) logic use retryWhen
:
subscription = ViewObservable.clicks(view, false)
.map(...)
.retryWhen(new Func1<Observable<?extends Notification<?>>, Observable<?>>() {
@Override
public Observable<?> call(Notification errorNotification) {
Throwablethrowable = errorNotification.getThrowable();
if (errorNotification.isOnError() && handleError(throwable)) {
// return the same observable to resubscribereturn Observable.just(errorNotification);
}
// return unhandled error to handle it in onError and unsubscribereturn Observable.error(throwable);
}
privateboolean handleError(Throwablethrowable) {
// handle your errors// return true if error handled to retry, false otherwisereturntrue;
}
}
.subscribe(subscriberA)
Post a Comment for "How To Subscribe To Click Events So Exceptions Don't Unsubscribe?"