Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
RxJava
Search
Douglas Kayama
August 29, 2015
Programming
5
580
RxJava
Palestra apresentada na QCon RJ 2015 e Android Dev Conference iMasters 2015
Douglas Kayama
August 29, 2015
Tweet
Share
More Decks by Douglas Kayama
See All by Douglas Kayama
TensorFlow no Android – v2
douglasdrumond
0
35
BLE
douglasdrumond
0
33
TensorFlow no Android
douglasdrumond
0
28
Firebase or Realm?
douglasdrumond
0
82
Rio Dev Day – Introdução ao Android
douglasdrumond
0
99
Google I/O
douglasdrumond
0
63
Criando apps com alto nível de qualidade (versão longa)
douglasdrumond
0
42
Criando apps com alto nível de qualidade (versão curta)
douglasdrumond
0
30
Primeiros Passos com Google Fit
douglasdrumond
0
200
Other Decks in Programming
See All in Programming
インターン生でもAuth0で認証基盤刷新が出来るのか
taku271
0
190
Kotlin Multiplatform Meetup - Compose Multiplatform 외부 의존성 아키텍처 설계부터 운영까지
wisemuji
0
190
AI前提で考えるiOSアプリのモダナイズ設計
yuukiw00w
0
220
Unicodeどうしてる? PHPから見たUnicode対応と他言語での対応についてのお伺い
youkidearitai
PRO
1
1.1k
CSC307 Lecture 05
javiergs
PRO
0
490
生成AIを使ったコードレビューで定性的に品質カバー
chiilog
1
220
フロントエンド開発の勘所 -複数事業を経験して見えた判断軸の違い-
heimusu
7
2.8k
CSC307 Lecture 02
javiergs
PRO
1
770
2026年 エンジニアリング自己学習法
yumechi
0
130
ZJIT: The Ruby 4 JIT Compiler / Ruby Release 30th Anniversary Party
k0kubun
1
390
SourceGeneratorのススメ
htkym
0
190
Package Management Learnings from Homebrew
mikemcquaid
0
180
Featured
See All Featured
Six Lessons from altMBA
skipperchong
29
4.1k
The SEO Collaboration Effect
kristinabergwall1
0
350
Utilizing Notion as your number one productivity tool
mfonobong
2
210
Redefining SEO in the New Era of Traffic Generation
szymonslowik
1
210
Code Review Best Practice
trishagee
74
20k
エンジニアに許された特別な時間の終わり
watany
106
230k
Docker and Python
trallard
47
3.7k
Leveraging LLMs for student feedback in introductory data science courses - posit::conf(2025)
minecr
0
130
Visualization
eitanlees
150
17k
What's in a price? How to price your products and services
michaelherold
247
13k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
2.7k
The innovator’s Mindset - Leading Through an Era of Exponential Change - McGill University 2025
jdejongh
PRO
1
88
Transcript
RxJava Douglas Drumond
[email protected]
whoami
None
Por que RxJava? Eventos de UI Eventos do domínio Concorrência
RxJava Observer pattern Iterator pattern Functional programming
Lambda
Retrolambda export JAVA_HOME=/path/java8 export JAVA7_HOME=/path/java7
Retrolambda plugins { id "me.tatarka.retrolambda" version "3.2.2" } android {
compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } }
Retrolambda view.setOnClickListener(new View. OnClickListener() { @Override public void onClick(final View
v) { ... } });
Retrolambda view.setOnClickListener(v -> { });
Básico Observables Subscribers Operadores
Observables Emite itens Chama onNext, onComplete ou onError Hot or
Cold
Subscriber Implementa onNext onComplete onError
Operadores flatMap filter debounce create defer etc
Criando Observable e Subscriber DEMO
Operators Subscribers reagem, não mudam Operadores transformam dados
Operators DEMO
Exemplo com UI DEMO
Mais operadores filter Ex: .filter(query -> !TextUtils.isEmpty(query))
Threads subscribeOn observeOn NewThreadScheduler HandlerThreadScheduler
Rede DEMO
Tratamento de erros Observable.create(...) .map(s -> exception(s)) .map(s -> exception2(s))
.subscribe(new Subscriber<String>() { @Override public void onNext(String s) { Log.d(TAG, s); } @Override public void onCompleted() { Log.d(TAG, "uhu!"); } @Override public void onError(Throwable e) { Log.e(TAG, "ops!"); } });
Ciclo de vida da Activity .cache .unsubscribe ao rodar .subscribe
ao restaurar Use RxLifecycle
Google Play Services https://github.com /mcharmas/Android-ReactiveLocation https://github.com /zmarkan/Reactive-PlayServices
Google Play Services ReactiveLocationProvider locationProvider = new ReactiveLocationProvider(context); locationProvider.getLastKnownLocation() .subscribe(new
Action1<Location>() { @Override public void call(Location location) { doSthImportantWithObtainedLocation(location); } });
Testes @Test public void shouldLoadTwoUsers() throw Exception { TestSubscriber<User> testSubscriber
= new TestSubscriber<>(); databaseHelper.loadUser().subscribe(testSubscriber); testSubscriber.assertNoErrors(); testSubscriber.assertReceivedOnNext( Arrays.asList(user1, user2)) }
Testes https://github.com/ribot/assertj-rx + BlockingObservable
Testes (exemplo) assertThat(observable.toBlocking()). completes(); assertThat(observable.toBlocking()) .completes() .listOfValuesEmitted() .containsExactly("a", "b", "c");
Referências http://reactivex.io/ https://github.com/ReactiveX/RxJava/wiki /Alphabetical-List-of-Observable-Operators https://speakerdeck.com/benjchristensen https://github.com/mutexkid/rxjava-koans
Referências https://github.com/trello/RxLifecycle https://github.com/JakeWharton/RxBinding https://github.com/ReactiveX/RxAndroid/
Código https://github.com/ douglasdrumond/KnightsOfLambdaCalculus
Obrigado
Contato
[email protected]
@douglasdrumond +DouglasDrumond www.cafelinear.com
[email protected]