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
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Douglas Kayama
August 29, 2015
Programming
580
5
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
RxJava
Palestra apresentada na QCon RJ 2015 e Android Dev Conference iMasters 2015
Douglas Kayama
August 29, 2015
More Decks by Douglas Kayama
See All by Douglas Kayama
TensorFlow no Android – v2
douglasdrumond
0
45
BLE
douglasdrumond
0
38
TensorFlow no Android
douglasdrumond
0
35
Firebase or Realm?
douglasdrumond
0
86
Rio Dev Day – Introdução ao Android
douglasdrumond
0
100
Google I/O
douglasdrumond
0
70
Criando apps com alto nível de qualidade (versão longa)
douglasdrumond
0
51
Criando apps com alto nível de qualidade (versão curta)
douglasdrumond
0
37
Primeiros Passos com Google Fit
douglasdrumond
0
200
Other Decks in Programming
See All in Programming
ビデオ通話が繋がる0.2秒で何が起きているのか
supurazako
2
150
【やさしく解説 設計編 #0】DDDのコード、読めるのに分からない人へ
panda728
PRO
2
280
ソフトウェア設計に溶けるインフラ ― AWS CDK のインフラ認識論
konokenj
3
670
「正の参照」と 「負の導出」で組む ハーネスエンジニアリング
cottpan
1
150
PHP Application における Kubernetes 内 gRPC 通信
ganchiku
0
550
メールのエイリアス機能を履き違えない
isshinfunada
0
110
自作OSでスライド発表する
uyuki234
1
4k
Claude Opus 4.6以後の受託開発エンジニアの変化(Claude Code開発ノウハウ大公開スペシャルbyクラスメソッド)
iidatakuma
1
890
What's New in Android 2026
veronikapj
0
230
광주소프트웨어마이스터고등학교 DevFest 특강 - 바이브 코딩 시대에서 주니어 개발자로 살아남는 방법
utilforever
1
160
AI時代のPHPer生存戦略 ~「言語、もうなんでもよくない?」に本気で向き合う~
vivion
0
190
Haskell/Servantを通してWebミドルウェアを捉え直す
pizzacat83
1
620
Featured
See All Featured
Why You Should Never Use an ORM
jnunemaker
PRO
61
9.9k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
32
3k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3.5k
Building the Perfect Custom Keyboard
takai
2
820
Designing for Performance
lara
611
70k
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
1
250
Optimising Largest Contentful Paint
csswizardry
37
3.8k
A designer walks into a library…
pauljervisheath
211
24k
A brief & incomplete history of UX Design for the World Wide Web: 1989–2019
jct
2
430
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
508
140k
Exploring the relationship between traditional SERPs and Gen AI search
raygrieselhuber
PRO
2
4.2k
Dominate Local Search Results - an insider guide to GBP, reviews, and Local SEO
greggifford
PRO
0
220
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]