I'm not quite understanding the difference between using an observable's doOnNext/doOnSubscribe/doOnComplete versus passing in an observer through the observable's subscribe function. These two seem to do the same thing to me. Can someone give me a use case where I would use one over the other?
Observable.interval(1, TimeUnit.SECONDS)
.take(30)
.map(v -> v + 1)
.observeOn(AndroidSchedulers.mainThread())
.doOnNext(new Consumer<Long>() {
@Override
public void accept(Long aLong) throws Throwable {
// update UI
}
})
Observable.interval(1, TimeUnit.SECONDS)
.take(30)
.map(v -> v + 1)
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Observer<Long>() {
@Override
public void onSubscribe(@NonNull Disposable d) {
}
@Override
public void onNext(@NonNull Long aLong) {
// update ui
}
@Override
public void onError(@NonNull Throwable e) {
}
@Override
public void onComplete() {
}
})