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
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
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
29
Firebase or Realm?
douglasdrumond
0
82
Rio Dev Day – Introdução ao Android
douglasdrumond
0
99
Google I/O
douglasdrumond
0
64
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
encoding/json/v2のUnmarshalはこう変わった:内部実装で見る設計改善
kurakura0916
0
370
Docコメントで始める簡単ガードレール
keisukeikeda
1
110
AI Assistants for Your Angular Solutions
manfredsteyer
PRO
0
120
AIに任せる範囲を安全に広げるためにやっていること
fukucheee
0
120
new(1.26) ← これすき / kamakura.go #8
utgwkk
0
1.9k
Go 1.26でのsliceのメモリアロケーション最適化 / Go 1.26 リリースパーティ #go126party
mazrean
1
370
AIとペアプロして処理時間を97%削減した話 #pyconshizu
kashewnuts
1
210
nilとは何か 〜interfaceの構造とnil!=nilから理解する〜
kuro_kurorrr
3
1.8k
どんと来い、データベース信頼性エンジニアリング / Introduction to DBRE
nnaka2992
1
260
エンジニアの「手元の自動化」を加速するn8n 2026.02.27
symy2co
0
110
ベクトル検索のフィルタを用いた機械学習モデルとの統合 / python-meetup-fukuoka-06-vector-attr
monochromegane
2
350
Claude Code、ちょっとした工夫で開発体験が変わる
tigertora7571
0
200
Featured
See All Featured
Sam Torres - BigQuery for SEOs
techseoconnect
PRO
0
210
Leveraging Curiosity to Care for An Aging Population
cassininazir
1
190
Applied NLP in the Age of Generative AI
inesmontani
PRO
4
2.1k
Introduction to Domain-Driven Design and Collaborative software design
baasie
1
630
Between Models and Reality
mayunak
2
230
SEOcharity - Dark patterns in SEO and UX: How to avoid them and build a more ethical web
sarafernandez
0
140
Deep Space Network (abreviated)
tonyrice
0
87
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
Darren the Foodie - Storyboard
khoart
PRO
3
2.8k
Mobile First: as difficult as doing things right
swwweet
225
10k
The #1 spot is gone: here's how to win anyway
tamaranovitovic
2
980
Digital Ethics as a Driver of Design Innovation
axbom
PRO
1
210
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]