Learn RxJava

Learn RxJava

In this example you can understand different elements of RxJava with Strings.

Simple
This method creates an Observable such that when an Observer subscribes, the onNext() of the Observer is immediately called with the argument provided to Observable.just(). The onCompleted() will then be called since the Observable has no other values to emit.

Observable.create(subcriber ->{
        subcriber.onNext("Hello");
        subcriber.onNext("Javier Gonzalez");
        subcriber.onCompleated();
    });

Now with Exception:

    Observable.create(subcriber ->{
        subcriber.onNext("Hello");
        subcriber.onNext("Javier Gonzalez");
        subcriber.onError(new Exception("iOS user now allowed"));
    });

And there are another different ways to do:

    Observable.just("Hello again...");

    Observable.from(Arrays.asList("Hello", "again..."));

    Observable.from(new String[]{"Hello", "again..."});

    Observable.concat(Observable.just("Hello"), Observable.just("again..."));

    Observable.merge(Observable.just("Hello", "again..."), Observable.never());

Also you can check this example
And this post

Leave a Reply

Your email address will not be published. Required fields are marked *