Reactive Programming Advantages/Disadvantages

Well, Reactive Programming means you are doing all your IO bound tasks such as network calls asynchronously. For an instance say your application calls an external REST API or a database, you can do that invocation asynchronously. If you do so your current thread does not block. You can serve lots of requests by merely … Read more

Subscribewith Vs subscribe in RxJava2(Android)?

Observable#subscribe explanation: In your first code snippet: .subscribe(this::handleResponse, this::handleError)); You are actually using one of the several overloaded Observable#subscribe methods: public final Disposable subscribe(Consumer<? super T> onNext, Consumer<? super Throwable> onError) There is another one that also takes in an Action to perform onComplete: public final Disposable subscribe(Consumer<? super T> onNext, Consumer<? super Throwable> onError, … Read more

Difference between RxJava API and the Java 9 Flow API

What are the main differences between these two libraries? The Java 9 Flow API is not a standalone library but a component of the Java Standard Edition library and consists of 4 interfaces adopted from the Reactive Streams specification established in early 2015. In theory, it’s inclusion can enable in-JDK specific usages, such as the … Read more

Android RxJava 2 JUnit test – getMainLooper in android.os.Looper not mocked RuntimeException

This error occurs because the default scheduler returned by AndroidSchedulers.mainThread() is an instance of LooperScheduler and relies on Android dependencies that are not available in JUnit tests. We can avoid this issue by initializing RxAndroidPlugins with a different Scheduler before the tests are run. You can do this inside of a @BeforeClass method like so: … Read more

How to use CompositeDisposable of RxJava 2?

private final CompositeDisposable disposables = new CompositeDisposable(); // adding an Observable to the disposable disposables.add(sampleObservable() .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribeWith(new DisposableObserver<String>() { @Override public void onComplete() { } @Override public void onError(Throwable e) { } @Override public void onNext(String value) { } })); static Observable<String> sampleObservable() { return Observable.defer(new Callable<ObservableSource<? extends String>>() { @Override public ObservableSource<? extends … Read more

How to chain two Completable in RxJava2

You are looking for andThen operator. Returns a Completable that first runs this Completable and then the other completable. firstCompletable .andThen(secondCompletable) In general, this operator is a “replacement” for a flatMap on Completable: Completable andThen(CompletableSource next) <T> Maybe<T> andThen(MaybeSource<T> next) <T> Observable<T> andThen(ObservableSource<T> next) <T> Flowable<T> andThen(Publisher<T> next) <T> Single<T> andThen(SingleSource<T> next)

Rxandroid What’s the difference between SubscribeOn and ObserveOn

SubscribeOn specify the Scheduler on which an Observable will operate. ObserveOn specify the Scheduler on which an observer will observe this Observable. So basically SubscribeOn is mostly subscribed (executed) on a background thread ( you do not want to block the UI thread while waiting for the observable) and also in ObserveOn you want to … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)