Creating custom logic for Disposable

In this post under RxJava, I will show with example how to add custom logic when a subscription between Observable and Observer is being disposed. You can add custom logic in Disposable only if you are creating an Observable using callback style. In my previous post under RxJava I have shown you how to create…… Continue reading Creating custom logic for Disposable

Using CompositeDisposable

In this post under RxJava, I will show with an example the purpose and how to use the CompositeDisposable class. When you have multiple subscriptions like shown below, we get a multiple Disposable object one for each subscription. Observable<Long> observable1 = Observable.interval(1000, TimeUnit.MILLISECONDS); Disposable disposable1 = observable1.subscribe((t) -> System.out.println(“Observable1: ” + t)); Observable<Long> observable2 =…… Continue reading Using CompositeDisposable

Disposing an automatically created Observer

In this post, I will explain how to dispose an automatically created Observer. In all my previous posts, when I provide the below code snippet, it was creating an Observer internally that will compose these lambda callback functions provided as arguments to the “subscribe” method. observable.subscribe(t -> System.out.println(t), t -> t.printStackTrace(), () -> System.out.println(“Complete”)); In…… Continue reading Disposing an automatically created Observer

Creating and Disposing an Observer Manually

In this post under RxJava, I will explain how to create and dispose an Observer manually. Till now in all my previous posts under RxJava, I was not creating and disposing an Observer manually. The Observer was created internally by RxJava. All I was doing was providing callback functions for onNext,onComplete, and onError events as…… Continue reading Creating and Disposing an Observer Manually

ConnectableObservable’s refCount method

In this post I will explain “refCount” method with an example. In my previous posts under RxJava, I explained about ConnectableObservable’s “autoConnect” method. This method is similar to “autoConnect” method. By calling refCount is nothing but calling autoConnect and passing 1 as an argument. Observable<Long> observable = Observable.interval(1, TimeUnit.SECONDS); observable = observable.publish().refCount(); is similar to…… Continue reading ConnectableObservable’s refCount method

ConnectableObservable autoConnect method

In this post under RxJava, I will explain with example the purpose of autoConnect method in ConnectableObservable class. We can use the autoConnect method to inform in advance how many observers will subscribe to the ConnectableObservable. Once the mentioned number of observers subscribe to the ConnectableObservable, the observable will behave like an cold observable and…… Continue reading ConnectableObservable autoConnect method