Creating Observables
To create an Observable, we can either create an Observable from scratch using the create function and calling Observer methods explicitly, or we can use built-in Observable creation methods that convert common data types to Observable streams.
Let's start with a simple example and create an observable that emits a String using the creating Observable.from operator:
Observable<String> myObservable =
Observable.from(Arrays.asList("Hello from RxJava",
"Welcome...",
"Goodbye"));The Observable.from static function creates Observable from an array that will synchronously emit String items to any Observer. The Observable created will be a cold Observable and will only start emitting events after an Observer subscribes to it.
Now, let's create a Subscriber that consumes the data and prints each String to the Android Log until Observable invokes the onComplete callback:
Subscriber<String> mySubscriber...