Send the link below via email or IMCopy
Present to your audienceStart remote presentation
- Invited audience members will follow you as you navigate and present
- People invited to a presentation do not need a Prezi account
- This link expires 10 minutes after you close the presentation
- A maximum of 30 users can follow your presentation
- Learn more about this feature in our knowledge base article
Reactive Android 101
Transcript of Reactive Android 101
How Did Reactive Happen?
Functional Reactive Programming
Invented in 1997
Started in academic languages
Represents data as how values change over time
Event streams > State
Created by Microsoft's Erik Meijer for C#.NET
Rx.NET brought the best ideas of FRP to a highly productive, business language
Created by Ben Christenson and his team at Netflix in 2013 to improve the resiliency of their networked services
Inspired by Rx.NET, Netflix provided a full port of reactive extensions for several JVM languages
Gang of Four
Four programmers publish a list of the most useful design patterns in 1994.
The Observer pattern becomes one of their most successful patterns.
Who IS This Guy?
Independent Android Engineer
Programming since age six
Races cars for fun
Electric auto enthusiast
Differences from Observer Pattern
Offers composable functions to manipulate event streams
An "Iterable Future"
Observables fill the gap by being the ideal way to access asynchronous sequences of multiple items
Do We Write Business Logic or Maintain State?
Observables offer an alternative to state variables.
Escape From Callback Hell
Deeply nested callbacks are hard to read and understand.
Named functions make callback hell worse.
Callbacks considered harmful.
Who Uses This?
"Netflix is a big believer in the Rx model, because Rx has made it much easier for us to build complex asynchronous programs.
RxJava is effective on the server for us and it spreads deeper into our code the more we use it."
"As things become more asynchronous, the functional model really fits well.
The ability to chain and transform async operations with hassle-free error propagation can be a powerful tool in any developer’s arsenal."
"Using RxJava to replace loaders and internal lib to replace fragments/activities. All that's left is views, android.animation.*, and bliss."
"Both our Android and iOS teams use the reactive programming paradigm to simplify asynchronous, concurrent code in our native mobile apps.
At SoundCloud, we are moving most of our code that relies heavily on event-based and asynchronous operations to Rx observables."
Networked Threading Gets Messy
AsyncTask is a Hack
Memory leaks common
Breaks on lifecycle events
Poor thread safety
Broken error handling
Convoluted logic for parallelism
If code gets subscribed to at the end of a chain, we know what came earlier.
What is a Subject?
Sometimes you want an Observable that is also an Observer. Input as well as output.
Subjects are useful for double binding models with views, as event buses, and for wrapping Observables.
Subjects break the Functional Programming contract with side effects, so they are best avoided when an Observable would also work.
When they're needed, they are really useful.
Breaking the Contract
When observing Subjects, they should always be cast to Observables.
A Subject's observers should never modify a Subject because to do so is evil. It tears up the contract.
Four Subject Behaviors
: Emits final value only after source Observable completes.
: Emits most recent value when subscribed then each value afterwards.
: Emits each value that occurs after subscription.
: Emits every value that occurred before subscription and then each value after.
Transform the Observable's type by applying a function.
Transform the items emitted by an Observable into Observables, then flatten this into a single Observable.
Filter items emitted by an Observable using a function which returns a boolean value.
Emit only the first n items.
Please take a moment to fill out
the class feedback form via the
app. Paper feedback forms are
also available in the back of the
All examples are on Github at:
It's easy to combine and chain observables.
The chain avoids race conditions and guarantees state is accurate.
Each marble represents an event.
Each line represents an observable.
Time flows to the right.
The chain flows down.