amitshekhariitbhu / RxJava2-Android-Samples

RxJava 2 Android Examples - How to use RxJava 2 in Android
https://outcomeschool.com
Apache License 2.0
4.96k stars 1.06k forks source link

Thread Interrupted #25

Open khaledkhj opened 6 years ago

khaledkhj commented 6 years ago

Any idea how to handle "thread interrupted"?

This happens due to calling the instant search api!

Thank you.

amitshekhariitbhu commented 6 years ago

We can handle that by using onErrorResumeNext.

khaledkhj commented 6 years ago

Thank you for the prompt reply, but can you please show an example on how to use it?

Apsaliya commented 6 years ago

I tried onErrorResumeNext without any luck. After InterruptedIOException it just won't emit. Looks like some ongoing request's Observable is getting unsubscribed at wrong time. Anyone got any idea?

Apsaliya commented 6 years ago

Ok, So for those who are still facing this, I managed to solve this by providing a scheduler to my switchMap . So unsubscribe on your previous calls won't affect on your current one.

SherifMuSherif commented 6 years ago

i had same issue "my subscription terminated once an error is emitted",but this one help me

.switchMap(new Func1<String, Observable<Response>>() {
    @Override public Observable<Response> call(String query) {
        return retrofitService.search(query)
                .onErrorResumeNext(Observable.<Response>empty());
    }
})

@khaledkhj @Apsaliya