Difference between doAfterTerminate and doFinally

The difference is that doFinally executes the provided Action if the downstream cancels/disposes the sequence in addition to the regular onError or onComplete termination paths. This allows cleaning up and releasing resources by all three means. The operator also guarantees that the action gets executed exactly once per subscription even in case if the onError … Read more

RxJava flatMapIterable with a Single

flattenAsObservable should do the trick, it will map Single success value to Iterable (list), and emit each item of the list as an Observable. getListOfItems() .flattenAsObservable(new Function<Object, Iterable<?>>() { @Override public Iterable<?> apply(@NonNull Object o) throws Exception { return toItems(o); } }) .flatMap(item -> doSomethingWithItem()) .toList()

How to reset a BehaviorSubject

I assume you want to clear the BehaviorSubject (because otherwise don’t call onComplete on it). That is not supported but you can achieve a similar effect by having a current value that is ignored by consumers: public static final Object EMPTY = new Object(); BehaviorSubject<Object> subject = BehaviorSubject.createDefault(EMPTY); Observable<YourType> obs = subject.filter(v -> v != … Read more

RxJava 2.x: Should I use Flowable or Single/Completable?

Backpressure is what you get when a source Observable is emitting items faster than a Subscriber can consume them. It’s most often a concern with hot observables, not cold ones like your network requests. I think you should use Completable instead of Observable<Void> in your saveUser method, and use Single for all places where you … Read more