SlideShare a Scribd company logo
Intro to RxJava on Android
Chris Arriola
Functional Reactive Programming
Makes dealing with concurrency easy
Makes code a lot more concise and readable
Encourages defensive programming and makes error handling easy
Increases the level of abstraction
Why consider RxJava?
Nested Network Call w/o RxJava
Nested Network Call w/ RxJava
What is RxJava?
Java implementation of .NET’s Reactive Extensions
Specification for Functional Reactive Programming (FRP)
Programming with asynchronous data streams
Not a new concept. Think: click events/handlers, event bus, etc.
Reactive part
Can combine, create, filter, map, or transform any stream
Core RxJava Constructs
● Observable
● Observer
● Operator
Emits items in a sequence
Like an Iterator, it produces all items in a sequence
Each emitted item will be propagated to each Observer
Observable
Observer
Observer (aka the “subscriber”) subscribes to Observable
Observers are notified of a new item through #onNext(...)
Observers are notified when there sequence completes/fails through
#onCompleted()/#onError()
Creating an Observable
● Create an Observable using #create(...)
Creating an Observable
● Create an Observable from item/s using #just(...)
● Create an Observable from an Iterable using #from(...)
● Create an Observable that emits items given an interval using #interval(...)
Creating an Observable (cont’d)
● Defer creation of Observable until subscription
Subscribing to an Observable
● Observer has #onNext(...), #onCompleted(...), and #onError(...)
Unsubscribing to an Observable
● Observable#subscribe(...) returns a Subscription object from which the
caller can invoke Subscription#unsubscribe()
Operator
● Most powerful part about Observables is that you can transform them and
perform functional style programming—map(), debounce(), filter(), etc.
● Transform Observable instances through Operators
Operator
Transforming an Observable
● Transform values emitted by Observable using the #map(...) operator
Filtering an Observable
● Filter values emitted by Observable using #filter(...) operator
Scheduling an Observable
● Specify a Scheduler where the Observable should operate using #subscribeOn(...),
specify a Scheduler where the Observable should notify its observers using
#observeOn(...)
Error Handling
● Re-subscribe/retry when the Observable emits an error
Ex. Double Clicks
Stream of clicks
Accumulate clicks in a list
Get length of list
Filter
Ex. Double Clicks
Simulate a stream of clicks:
Ex. Double Clicks
Accumulate clicks until 250 ms has passed between clicks:
Ex. Double Clicks
Map the length of each list & filter for sizes >= 2:
Introduction to RxJava on Android
GitHub Example
● Interact with GitHub’s API using Retrofit and RxJava
○ https://github.com/arriolac/GithubRxJava
Questions??
Thank You!
Twitter: @arriolachris

More Related Content

PDF
RxJava@Android
Maxim Volgin
 
PDF
The Mayans Lost Guide to RxJava on Android
Fernando Cejas
 
PDF
Streams, Streams Everywhere! An Introduction to Rx
Andrzej Sitek
 
ODP
Functional programming in Javascript
Knoldus Inc.
 
PPTX
Code craftsmanship saturdays second session
Jean Marcel Belmont
 
PDF
Introduction to RxJS
Brainhub
 
ODP
Functors, Applicatives and Monads In Scala
Knoldus Inc.
 
PPTX
Functional programing jargon
Remo Jansen
 
RxJava@Android
Maxim Volgin
 
The Mayans Lost Guide to RxJava on Android
Fernando Cejas
 
Streams, Streams Everywhere! An Introduction to Rx
Andrzej Sitek
 
Functional programming in Javascript
Knoldus Inc.
 
Code craftsmanship saturdays second session
Jean Marcel Belmont
 
Introduction to RxJS
Brainhub
 
Functors, Applicatives and Monads In Scala
Knoldus Inc.
 
Functional programing jargon
Remo Jansen
 

What's hot (20)

PPTX
Functional programming
Lhouceine OUHAMZA
 
PPTX
Java 8 streams
Srinivasan Raghvan
 
PPTX
Linq
samneang
 
PDF
Effective java item 80 and 81
Isaac Liao
 
PDF
Cocoa heads 09112017
Vincent Pradeilles
 
PPT
Module 3: Introduction to LINQ (PowerPoint Slides)
Mohamed Saleh
 
ODP
OCL 2.4. (... 2.5)
Edward Willink
 
PDF
Asynchronous JavaScript Programming with Callbacks & Promises
Hùng Nguyễn Huy
 
ODP
At Last an OCL Debugger
Edward Willink
 
PPTX
Link quries
ulfat mushtaq
 
PPTX
Functional Reactive Endpoints using Spring 5
Rory Preddy
 
ODP
Safe navigation in OCL
Edward Willink
 
ODP
The OCLforUML Profile
Edward Willink
 
PPT
Linq
Vishwa Mohan
 
PDF
Callback Function
Roland San Nicolas
 
PDF
JSAnkara Swift v React Native
Muhammed Demirci
 
PDF
Intro to Asynchronous Javascript
Garrett Welson
 
PPT
Java 8 Streams
Manvendra Singh
 
PPTX
Introduction to RxJS
Abul Hasan
 
Functional programming
Lhouceine OUHAMZA
 
Java 8 streams
Srinivasan Raghvan
 
Linq
samneang
 
Effective java item 80 and 81
Isaac Liao
 
Cocoa heads 09112017
Vincent Pradeilles
 
Module 3: Introduction to LINQ (PowerPoint Slides)
Mohamed Saleh
 
OCL 2.4. (... 2.5)
Edward Willink
 
Asynchronous JavaScript Programming with Callbacks & Promises
Hùng Nguyễn Huy
 
At Last an OCL Debugger
Edward Willink
 
Link quries
ulfat mushtaq
 
Functional Reactive Endpoints using Spring 5
Rory Preddy
 
Safe navigation in OCL
Edward Willink
 
The OCLforUML Profile
Edward Willink
 
Callback Function
Roland San Nicolas
 
JSAnkara Swift v React Native
Muhammed Demirci
 
Intro to Asynchronous Javascript
Garrett Welson
 
Java 8 Streams
Manvendra Singh
 
Introduction to RxJS
Abul Hasan
 
Ad

Similar to Introduction to RxJava on Android (20)

PDF
响应式编程及框架
jeffz
 
PPTX
Introduction to Reactive programming
Dwi Randy Herdinanto
 
PDF
RxJava for Android - GDG DevFest Ukraine 2015
Constantine Mars
 
PDF
ReactiveCocoa in Practice
Outware Mobile
 
PPT
Reactive programming
BeauLiu
 
PDF
The Evolution of Async-Programming on .NET Platform (.Net China, C#)
jeffz
 
PDF
Angular 16 – the rise of Signals
Coding Academy
 
PDF
Reactive Streams and RxJava2
Yakov Fain
 
PDF
Integration-Monday-Stateful-Programming-Models-Serverless-Functions
BizTalk360
 
PDF
Reactive java - Reactive Programming + RxJava
NexThoughts Technologies
 
PDF
Reactive Thinking in iOS Development - Pedro Piñera Buendía - Codemotion Amst...
Codemotion
 
PDF
Observables in Angular
Knoldus Inc.
 
PDF
Workshop 13: AngularJS Parte II
Visual Engineering
 
PDF
Reactive systems
Naresh Chintalcheru
 
PPTX
Reactive Java (GeeCON 2014)
Tomasz Kowalczewski
 
PDF
Understanding the Android System Server
Opersys inc.
 
PDF
Concurrecny inf sharp
Riccardo Terrell
 
PDF
The Evolution of Async-Programming (SD 2.0, JavaScript)
jeffz
 
PPTX
Reactive Programming no Android
Guilherme Branco
 
PDF
Nicholas Gustilo "Clean Android: building great mobile apps"
IT Event
 
响应式编程及框架
jeffz
 
Introduction to Reactive programming
Dwi Randy Herdinanto
 
RxJava for Android - GDG DevFest Ukraine 2015
Constantine Mars
 
ReactiveCocoa in Practice
Outware Mobile
 
Reactive programming
BeauLiu
 
The Evolution of Async-Programming on .NET Platform (.Net China, C#)
jeffz
 
Angular 16 – the rise of Signals
Coding Academy
 
Reactive Streams and RxJava2
Yakov Fain
 
Integration-Monday-Stateful-Programming-Models-Serverless-Functions
BizTalk360
 
Reactive java - Reactive Programming + RxJava
NexThoughts Technologies
 
Reactive Thinking in iOS Development - Pedro Piñera Buendía - Codemotion Amst...
Codemotion
 
Observables in Angular
Knoldus Inc.
 
Workshop 13: AngularJS Parte II
Visual Engineering
 
Reactive systems
Naresh Chintalcheru
 
Reactive Java (GeeCON 2014)
Tomasz Kowalczewski
 
Understanding the Android System Server
Opersys inc.
 
Concurrecny inf sharp
Riccardo Terrell
 
The Evolution of Async-Programming (SD 2.0, JavaScript)
jeffz
 
Reactive Programming no Android
Guilherme Branco
 
Nicholas Gustilo "Clean Android: building great mobile apps"
IT Event
 
Ad

Recently uploaded (20)

PPTX
anatomy of limbus and anterior chamber .pptx
ZePowe
 
PPTX
Unit 5 BSP.pptxytrrftyyydfyujfttyczcgvcd
ghousebhasha2007
 
PPTX
MET 305 MODULE 1 KTU 2019 SCHEME 25.pptx
VinayB68
 
PDF
Monitoring Global Terrestrial Surface Water Height using Remote Sensing - ARS...
VICTOR MAESTRE RAMIREZ
 
PPTX
Edge to Cloud Protocol HTTP WEBSOCKET MQTT-SN MQTT.pptx
dhanashri894551
 
PPTX
Module_II_Data_Science_Project_Management.pptx
anshitanarain
 
PPTX
ANIMAL INTERVENTION WARNING SYSTEM (4).pptx
dodultrongaming
 
PDF
A Framework for Securing Personal Data Shared by Users on the Digital Platforms
ijcncjournal019
 
PDF
July 2025: Top 10 Read Articles Advanced Information Technology
ijait
 
PPT
SCOPE_~1- technology of green house and poyhouse
bala464780
 
PPTX
Simulation of electric circuit laws using tinkercad.pptx
VidhyaH3
 
PPTX
AgentX UiPath Community Webinar series - Delhi
RohitRadhakrishnan8
 
PPTX
TE-AI-Unit VI notes using planning model
swatigaikwad6389
 
PDF
algorithms-16-00088-v2hghjjnjnhhhnnjhj.pdf
Ajaykumar966781
 
PPTX
Azure-DevOps-Training presentation downloadable
NamanGoyal428595
 
PDF
Top 10 read articles In Managing Information Technology.pdf
IJMIT JOURNAL
 
PPTX
Ship’s Structural Components.pptx 7.7 Mb
abdalwhab7327
 
PDF
오픈소스 LLM, vLLM으로 Production까지 (Instruct.KR Summer Meetup, 2025)
Hyogeun Oh
 
PDF
Queuing formulas to evaluate throughputs and servers
gptshubham
 
anatomy of limbus and anterior chamber .pptx
ZePowe
 
Unit 5 BSP.pptxytrrftyyydfyujfttyczcgvcd
ghousebhasha2007
 
MET 305 MODULE 1 KTU 2019 SCHEME 25.pptx
VinayB68
 
Monitoring Global Terrestrial Surface Water Height using Remote Sensing - ARS...
VICTOR MAESTRE RAMIREZ
 
Edge to Cloud Protocol HTTP WEBSOCKET MQTT-SN MQTT.pptx
dhanashri894551
 
Module_II_Data_Science_Project_Management.pptx
anshitanarain
 
ANIMAL INTERVENTION WARNING SYSTEM (4).pptx
dodultrongaming
 
A Framework for Securing Personal Data Shared by Users on the Digital Platforms
ijcncjournal019
 
July 2025: Top 10 Read Articles Advanced Information Technology
ijait
 
SCOPE_~1- technology of green house and poyhouse
bala464780
 
Simulation of electric circuit laws using tinkercad.pptx
VidhyaH3
 
AgentX UiPath Community Webinar series - Delhi
RohitRadhakrishnan8
 
TE-AI-Unit VI notes using planning model
swatigaikwad6389
 
algorithms-16-00088-v2hghjjnjnhhhnnjhj.pdf
Ajaykumar966781
 
Azure-DevOps-Training presentation downloadable
NamanGoyal428595
 
Top 10 read articles In Managing Information Technology.pdf
IJMIT JOURNAL
 
Ship’s Structural Components.pptx 7.7 Mb
abdalwhab7327
 
오픈소스 LLM, vLLM으로 Production까지 (Instruct.KR Summer Meetup, 2025)
Hyogeun Oh
 
Queuing formulas to evaluate throughputs and servers
gptshubham
 

Introduction to RxJava on Android

Editor's Notes

  • #2: About this talk What: RxJava basics RxJava + Android + Coding towards the end What Not: Not a talk about functional programming Not a talk about in depths of RxJava, goal is to pique your interest in integrating RxJava in your project About me
  • #3: Concurrency - #1 reason. mobile is inherently concurrently. Best abstractions around dealing with concurrency Concise - very easy to follow the flow and transformation of data Defensive programming - very simple constructs that make dealing with various edge cases easier Code behave in a more predictable manner Level of abstraction - the reason why it provides all these benefits
  • #4: Callback hell Poor readability - caused by deep nesting Error prone Failing in between When it comes to readability you want to think of this as a tree data structure
  • #5: 1. Removes the need for callbacks End result is all in one place (Action1) Error handling is all in one place (doOnError) 2. Improved readability 3. Operation is a sequence of stream transformations
  • #6: .NET Reactive Extension - 2009, RxJava - 2012. Functional Reactive Programming Everything is a stream. If you are familiar with Futures, Iterables, and Observer - it’s a combination of those
  • #7: 3 concepts that are the foundation of RxJava
  • #8: The RxJava representation of a stream Atomic unit in Rx Something that can be observed
  • #9: Looks a lot like the Gang of Four Observer design pattern. The main difference is that Observables only start emitting once a subscriber subscribes.
  • #10: Pass in a class that implements OnSubscribe()
  • #11: Convenience methods for creating an Observable Finite vs. infinite stream
  • #12: Defer execution until subscription - this guarantees that the factory passed in #defer() only executes when #subscribe(...) is invoked. Ideal with long operations
  • #13: What gets logged in this example? Observer/Subscriber are sometimes used interchangeably. The Observer is the interface and a Subscriber is an implementation of an Observer
  • #14: Unsubscribe whenever the observer is no longer interested in the result
  • #15: Observable and Observer are independent of the transformational steps that occur in between A dozen operators that exist and we won’t be talking about all of them but I’ll mention a few that I think are commonly used
  • #16: ++ documentation Operators act in between emissions by Observables and receives by Observers
  • #17: Rxjava has a huge collection of Operators but I want to focus on some really common operators Observables provide a fluid interface
  • #18: Can’t you just surround with if statement? Goes back to defensive programming
  • #19: Think of Scheduler as an Executor By default, an Observable and the chain of operators that you apply to it will do its work, and will notify its observers, on the same thread on which its Subscribe method is called
  • #20: Network call
  • #22: Click every 250ms, add a delay of [0, 250]ms between clicks
  • #23: Using the Observable creation methods we mentioned earlier, the created Observable is considered a cold observable publish().refCount() turns this Observable to a hot Observable
  • #26: Done with talk on RxJava -> Now talk about integrating RxJava in Android One of the best applications of RxJava is for networking RxJava + Retrofit