RxJava? What is it?
RxKotlin/RxJava provides an easy and efficient way to handle asynchronous stream of data in programs running on Java Virtual Machine (JVM).
Some examples of asynchronous events can be Network Requests, Touch Input Events etc.
Rx in RxKotlin stands for Reactive Extensions.
On Android when it comes to handling operations that must be done off the UI thread there are a lot of options like AsyncTask, Loaders, JobDispatcher etc.
and what makes RxJava stand out is its flexibility and power of Rx Operators.
But for a novice Android Developer the terminologies and concepts used in RxJava world can be intimidating.
Add this to the build.gradle (app level) module file.
Here are the three important terms that you would come across in Rx World:
It is someone that observers or requires the data/event from.
It is someone who subscribes to the observable
Is someone/something that emits/produces a stream(s) data which can be observed by the Observer/Subscriber who subscribes to it.
Here’s how you would make a simple observable that emits/produces 3 integers:
Here’s how you would create a Flowable from a list:
Operations that can be performed on the stream of data or observables themselves.
Some Operators on Observables:
To learn more on Operators, check out Rx Marbles (link below)
- RxJava (Github)
- Intro to RxJava by Christina Lee
- RxKotlin (Github)
- Rx Marbles
- Exploring RxJava (my favorite article where I learn RxJava from)