This document introduces RxJava and RxAndroid. It explains that RxJava allows for composing asynchronous and event-based programs using observable sequences. It covers how to create Observables, subscribe to them, use operators to transform data, and handle threading. It also discusses how RxJava is useful for Android development by making asynchronous code easier to write, test, and handle threading, with libraries like RxAndroid, RxBinding, and RxLifecycle to integrate with Android components and lifecycles.
4. “RXJAVA IS A JAVA VM IMPLEMENTATION OF
REACTIVEX (REACTIVE EXTENSIONS): A
LIBRARY FOR COMPOSING ASYNCHRONOUS
AND EVENT-BASED PROGRAMS BY USING
OBSERVABLE SEQUENCES.”
RxJava Wiki
WHAT IS RXJAVA?
8. HOW RXJAVA?
THE HIGH LEVEL PLAN
▸ Create an Observable
▸ Manipulate data using operators
▸ Subscribe and consume
▸ Profit!
9. HOW RXJAVA?
CREATING OBSERVABLES: CREATE()
Observable.create(subscriber -> {
try {
for (int value = 1; value <= 3; value++) {
subscriber.onNext(value);
}
subscriber.onCompleted();
} catch (Throwable t) {
subscriber.onError(t);
}
});
10. HOW RXJAVA?
THE OBSERVER INTERFACE
public interface Observer<T> {
void onCompleted();
void onError(Throwable e);
void onNext(T t);
}
11. HOW RXJAVA?
THE NOTIFICATIONS CONTRACT
▸ Zero or more onNext() notifications
▸ Either onCompleted() or onError(), not both!
▸ Nothing more!
▸ May never terminate
▸ May never call onCompleted()
▸ All notifications must be issued serially