-
Notifications
You must be signed in to change notification settings - Fork 6.3k
RxJava
RxJava is a library built for Java that is used to help write in a style known as [reactive programming] (https://gist.github.com/staltz/868e7e9bc2a7b8c1f754#what-is-reactive-programming). Reactive programming often requires a significant mindset shift from traditional approaches because it means thinking of everything as processing asynchronous data streams. Not only are mouse clicks asynchronous data streams, but also network calls, database fetches, or cache retrievals could be considered as well.
Imagine trying to perform a series of chained tasks using AsyncTask. We could implement the dispatching on the onPostExecute()
of each task, but writing code to dispatch certain tasks depending on certain states will end up cause endless complicated code. Reactive programming helps provide an abstraction layer that describes how these events should be sequenced.
Reactive programming also provides an abstraction layer to combine, create, or filter them in a way that is easier to understand and maintain for the developer.
Advantages of using RxJava:
- Powerful constructs for manipulating streams of data.
- Helps control the threading on which the work happens and when the callbacks are fired.
Setup your app/build.gradle
:
dependencies {
compile 'io.reactivex:rxjava:1.0.16'
compile 'io.reactivex:rxandroid:1.0.1'
}
- https://github.com/ReactiveX/RxJava/wiki/The-RxJava-Android-Module
- http://saulmm.github.io/when-Iron-Man-becomes-Reactive-Avengers2/
- http://blog.stablekernel.com/replace-asynctask-asynctaskloader-rx-observable-rxjava-android-patterns/
- https://www.youtube.com/watch?v=_t06LRX0DV0/
- https://vimeo.com/144812843
Created by CodePath with much help from the community. Contributed content licensed under cc-wiki with attribution required. You are free to remix and reuse, as long as you attribute and use a similar license.
Finding these guides helpful?
We need help from the broader community to improve these guides, add new topics and keep the topics up-to-date. See our contribution guidelines here and our topic issues list for great ways to help out.
Check these same guides through our standalone viewer for a better browsing experience and an improved search. Follow us on twitter @codepath for access to more useful Android development resources.