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 ...
Get Asynchronous Android Programming - Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.