Rxjava / rxbinding: how to handle errors on rxview
•
Java
I use RX Java and rxbindings to view in Android Here's an example of what I'm doing
RxView.clicks(btMyButton).flatMap(btn -> {
// another observable which can throw onError.
return Observable.error(null);
}).subscribe(object -> {
Log.d("CLICK","button clicked");
},error -> {
Log.d("CLICK","ERROR");
});
When I click my button, I use flatmap to return another observable, which is a network call that can return success or error When it returns an error, I process it in the error block But I can't click the button again
How do I handle the error and still click the button again?
Solution
Grey bearded geek is spot To specify one of your options, you can use materialize():
RxView.clicks(btMyButton).flatMap(btn -> {
if (ok)
return someObservable.materialize();
else
return Observable.error(new MyException()).materialize();
}).subscribe(notification -> {
if (notification.hasValue())
Log.d("CLICK","button clicked");
else if (notification.isOnError())
Log.d("CLICK","ERROR");
});
By the way, don't pass null to observable error().
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码
