When you received an error with this message
rx.exceptions.OnErrorFailedException: Error occurred when trying to propagate error to Observer.onError
but your subscription is already handling onError
MyMethodThatRetunsAnObservable(string)
.subscribe(
response -> handleResponse(response),
throwable -> handleError(throwable));
In case that is caused by: java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
Note that onError notifications will cut ahead of onNext notifications on the emission thread if Scheduler is truly asynchronous. So it's needed to specify the UI Thread in which we are going to observe
public static void shortToast(String msg) {
Observable.just(msg)
.subscribeOn(AndroidSchedulers.mainThread())
.subscribe(message -> {
Toast.makeText(App.getInstance(), message, Toast.LENGTH_SHORT).show();
});
}
yes, you got the error. You should call subscribeOn(AndroidSchedulers.mainThread() instead of observerOn. The show log function was called before the observerOn and called in the onSubcribe method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With