Mohit Kumar Mohit Kumar - 3 months ago 61
Android Question

How to use SingleObserver, Single of RxJava 2?

RxJava2 has been changed a lot. It has too much differences over RxJava1. Anybody Examples on how to use SingleObserver, Single of RxJava2 ? Any help will be appreciated.

Answer
private void doSomeWork() {
    Single.just("Amit")
            .subscribe(getSingleObserver());
}

private SingleObserver<String> getSingleObserver() {
    return new SingleObserver<String>() {
        @Override
        public void onSubscribe(Disposable d) {
        }

        @Override
        public void onSuccess(String value) {
        }

        @Override
        public void onError(Throwable e) {
        }
    };
}

I have a create a sample project to demonstrate the use of RxJava2. Here you can find the sample project - RxJava2-Android-Samples

Comments