What is CompositeDisposable in RxJava

Composite disposable makes disposing (think cancelling early) easier. Say you have an activity that has multiple api calls happening at once: var disposable = api.call1(arg1, arg2).subscribe(…) var disposable2 = api.call2(arg1).subscribe(…) var disposable3 = api.call3().subscribe() If you need to prematurely dispose (e.g. the user navigating away from the activity) then you’d need to do this: disposable.dispose() … Read more

RxJava: difference between doOnNext and doOnEach

They are indeed quite close. One thing that differs (and it’s maybe not that clear in the javadoc actually, more visible in sourcecode) is that in doOnEach, you also get Notification wrappers for errors and completion event. You can then check isOnNext, isOnCompleted or isOnError to check the actual kind of event you got a … Read more

How to ignore error and continue infinite stream?

You may want to use one of the error handling operators. onErrorResumeNext( ) — instructs an Observable to emit a sequence of items if it encounters an error onErrorReturn( ) — instructs an Observable to emit a particular item when it encounters an error onExceptionResumeNext( ) — instructs an Observable to continue emitting items after it encounters an … Read more

Concat VS Merge operator

It is as described in documentation you have quoted – merge can interleave the outputs, while concat will first wait for earlier streams to finish before processing later streams. In your case, with single-element, static streams, it is not making any real difference (but in theory, merge could output words in random order and still … Read more

How to create a retrofit.Response object during Unit Testing with Retrofit 2

The retrofit.Response class has static factory methods to create instances: public static <T> Response<T> success(T body) { /* … */ } public static <T> Response<T> success(T body, com.squareup.okhttp.Response rawResponse) { /* … */ } public static <T> Response<T> error(int code, ResponseBody body) { /* … */ } public static <T> Response<T> error(ResponseBody body, com.squareup.okhttp.Response rawResponse) … Read more