SlideShare uma empresa Scribd logo
1 de 25
Baixar para ler offline
RxJava with retrolambda
introduction
Andyang@2015/12/26
RxJava (x)
RxJava (o)
lifecycle memory leak
callback hell
error handling
lambda
API
XD
Retrolambda
Android N Java8
retrolambda library support lambda
jdk8
support java6/7
android support java8 

gradle
retrolambda setting on
android studio
apply plugin: 'me.tatarka.retrolambda'
buildscript {

repositories {

mavenCentral()

}



dependencies {

classpath 'me.tatarka:gradle-retrolambda:3.2.4'

}

}
compileOptions {

sourceCompatibility JavaVersion.VERSION_1_8

targetCompatibility JavaVersion.VERSION_1_8

}
lambda#1
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
System.out.println("click")
}
});
// lambda
button.setOnClickListener(view -> System.out.println("click"));
lambda#2
input -> body
view -> System.out.println("click")
lambda#3
intput
void
() -> body
x -> System.out.println(x)
(x, y) -> x + y;
(int x, int y) -> x + y;
lambda#4
() -> {}
{}
(x, y) -> x + y;
(x, y) -> x + y
lambda#5
(x, y) ->{
x * x;
y * y;
}
(x, y) ->{
x * x;
y * y;
return x + y;
}
lambda#6
Object reference
view.setOnClickListener(v -> v.setVisibility(View.GONE));
view.setOnClickListener(this::viewGone);
private void viewGone(View v){

v.setVisibility(View.GONE);

}
RxJava
pub/sub
RxJava setting on
android studio
RxAnroid
compile ‘io.reactivex:rxandroid:1.1.0'
RxLifecycle
compile 'com.trello:rxlifecycle:0.4.0'

compile 'com.trello:rxlifecycle-components:
0.4.0'
AsyncTask
class MyTask extends AsyncTask<String, Integer, String>
{



@Override

protected String doInBackground(String... params) {

return null;

}



@Override

protected void onPostExecute(String s) {

super.onPostExecute(s);

}

}
RxJava
//Observable
api.getPets()
//Scheduler 

.subscribeOn(Schedulers.newThread())

.observeOn(AndroidSchedulers.mainThread())
//Observer

.subscribe();
Observable
Observable.create(subscriber -> {

subscriber.onNext("");

subscriber.onCompleted();

subscriber.onError(null);

});
api.getPets()

.compose(bindToLifecycle())

.map(petsResponse ->
petsResponse.getResult().getResults())

.retry(this::networkRetry)

.subscribeOn(Schedulers.newThread())

.observeOn(AndroidSchedulers.mainThread())

.finallyDo(dialog::dismiss)

.subscribe(adapter::setPets, this::showErrorLog,
this::onComplete);
private boolean networkRetry(int times, Throwable throwable)
{

RetrofitError retrofitError = (RetrofitError) throwable;

return retrofitError.getKind() ==
RetrofitError.Kind.NETWORK || times < 3;

}
DEMO
4 sample
Sample 1 : api
DEMO
Sample 2 :
DEMO
Sample 3:
DEMO
Sample 4:
DEMO
sample code
1.https://github.com/bng86/RxJavaWithRetrolambdaSample
1.https://www.youtube.com/watch?v=k3D0cWyNno4
2.https://github.com/kaushikgopal/RxJava-Android-
Samples
3.https://mcxiaoke.gitbooks.io/rxdocs/content/Intro.html
Q&A

Mais conteúdo relacionado

Mais procurados

Overview of Android Infrastructure
Overview of Android InfrastructureOverview of Android Infrastructure
Overview of Android Infrastructure
Alexey Buzdin
 
PROMAND 2014 project structure
PROMAND 2014 project structurePROMAND 2014 project structure
PROMAND 2014 project structure
Alexey Buzdin
 
Diversified AT Framework - Initial Version
Diversified AT Framework - Initial VersionDiversified AT Framework - Initial Version
Diversified AT Framework - Initial Version
Yu Tao Zhang
 

Mais procurados (20)

Android Loaders : Reloaded
Android Loaders : ReloadedAndroid Loaders : Reloaded
Android Loaders : Reloaded
 
Overview of Android Infrastructure
Overview of Android InfrastructureOverview of Android Infrastructure
Overview of Android Infrastructure
 
Тестирование на Android с Dagger 2
Тестирование на Android с Dagger 2Тестирование на Android с Dagger 2
Тестирование на Android с Dagger 2
 
Java 9 preview
Java 9 previewJava 9 preview
Java 9 preview
 
PROMAND 2014 project structure
PROMAND 2014 project structurePROMAND 2014 project structure
PROMAND 2014 project structure
 
Retrofit
RetrofitRetrofit
Retrofit
 
Dropwizard and Friends
Dropwizard and FriendsDropwizard and Friends
Dropwizard and Friends
 
GradleFX
GradleFXGradleFX
GradleFX
 
Idiomatic Gradle Plugin Writing - GradleSummit 2016
Idiomatic Gradle Plugin Writing - GradleSummit 2016Idiomatic Gradle Plugin Writing - GradleSummit 2016
Idiomatic Gradle Plugin Writing - GradleSummit 2016
 
Highlights from Java 10-13 and Future of Java at JCON 2019 by Alukhanov and K...
Highlights from Java 10-13 and Future of Java at JCON 2019 by Alukhanov and K...Highlights from Java 10-13 and Future of Java at JCON 2019 by Alukhanov and K...
Highlights from Java 10-13 and Future of Java at JCON 2019 by Alukhanov and K...
 
Diversified AT Framework - Initial Version
Diversified AT Framework - Initial VersionDiversified AT Framework - Initial Version
Diversified AT Framework - Initial Version
 
Making the most of your gradle build - Gr8Conf 2017
Making the most of your gradle build - Gr8Conf 2017Making the most of your gradle build - Gr8Conf 2017
Making the most of your gradle build - Gr8Conf 2017
 
Making the most of your gradle build - Greach 2017
Making the most of your gradle build - Greach 2017Making the most of your gradle build - Greach 2017
Making the most of your gradle build - Greach 2017
 
Angular 2 Migration - JHipster Meetup 6
Angular 2 Migration - JHipster Meetup 6Angular 2 Migration - JHipster Meetup 6
Angular 2 Migration - JHipster Meetup 6
 
Docker In Bank Unrated
Docker In Bank UnratedDocker In Bank Unrated
Docker In Bank Unrated
 
Enter the gradle
Enter the gradleEnter the gradle
Enter the gradle
 
State management in a GraphQL era
State management in a GraphQL eraState management in a GraphQL era
State management in a GraphQL era
 
The Making of the Oracle R2DBC Driver and How to Take Your Code from Synchron...
The Making of the Oracle R2DBC Driver and How to Take Your Code from Synchron...The Making of the Oracle R2DBC Driver and How to Take Your Code from Synchron...
The Making of the Oracle R2DBC Driver and How to Take Your Code from Synchron...
 
0900 learning-react
0900 learning-react0900 learning-react
0900 learning-react
 
JEEConf 2017 - The hitchhiker’s guide to Java class reloading
JEEConf 2017 - The hitchhiker’s guide to Java class reloadingJEEConf 2017 - The hitchhiker’s guide to Java class reloading
JEEConf 2017 - The hitchhiker’s guide to Java class reloading
 

Destaque

Android動態ui介面設計
Android動態ui介面設計Android動態ui介面設計
Android動態ui介面設計
艾鍗科技
 

Destaque (15)

ORMLite Android
ORMLite AndroidORMLite Android
ORMLite Android
 
設計師合作經驗分享
設計師合作經驗分享設計師合作經驗分享
設計師合作經驗分享
 
Orm各library效能分析與使用
Orm各library效能分析與使用Orm各library效能分析與使用
Orm各library效能分析與使用
 
Hybrid design with bootstrap
Hybrid design with bootstrapHybrid design with bootstrap
Hybrid design with bootstrap
 
Custom view2
Custom view2Custom view2
Custom view2
 
Gson
GsonGson
Gson
 
Dog point
Dog pointDog point
Dog point
 
FcmD2D
FcmD2DFcmD2D
FcmD2D
 
Android Crawler Web
Android Crawler WebAndroid Crawler Web
Android Crawler Web
 
Unit test and ui testing with cucumber
Unit test and ui testing with cucumberUnit test and ui testing with cucumber
Unit test and ui testing with cucumber
 
Android Animator
Android AnimatorAndroid Animator
Android Animator
 
Firebase Cloud Messaging Device to Device
Firebase Cloud Messaging Device to DeviceFirebase Cloud Messaging Device to Device
Firebase Cloud Messaging Device to Device
 
(ARC206) Architecting Reactive Applications on AWS | AWS re:Invent 2014
(ARC206) Architecting Reactive Applications on AWS | AWS re:Invent 2014(ARC206) Architecting Reactive Applications on AWS | AWS re:Invent 2014
(ARC206) Architecting Reactive Applications on AWS | AWS re:Invent 2014
 
Android動態ui介面設計
Android動態ui介面設計Android動態ui介面設計
Android動態ui介面設計
 
Kotlin 初體驗
Kotlin 初體驗Kotlin 初體驗
Kotlin 初體驗
 

Semelhante a RxJava With retrolambda

Web polyglot programming
Web polyglot programmingWeb polyglot programming
Web polyglot programming
Dmitry Buzdin
 
Paug paris 2011
Paug paris 2011Paug paris 2011
Paug paris 2011
sekond0
 

Semelhante a RxJava With retrolambda (20)

Developing android apps with java 8
Developing android apps with java 8Developing android apps with java 8
Developing android apps with java 8
 
Introduction to Retrofit and RxJava
Introduction to Retrofit and RxJavaIntroduction to Retrofit and RxJava
Introduction to Retrofit and RxJava
 
Native Java with GraalVM
Native Java with GraalVMNative Java with GraalVM
Native Java with GraalVM
 
JCConf2019: Next Step of JavaScript on Java
JCConf2019: Next Step of JavaScript on JavaJCConf2019: Next Step of JavaScript on Java
JCConf2019: Next Step of JavaScript on Java
 
Eric Lafortune - The Jack and Jill build system
Eric Lafortune - The Jack and Jill build systemEric Lafortune - The Jack and Jill build system
Eric Lafortune - The Jack and Jill build system
 
Java 8 Lambda
Java 8 LambdaJava 8 Lambda
Java 8 Lambda
 
Rx java in action
Rx java in actionRx java in action
Rx java in action
 
Adopting GraalVM - Scale by the Bay 2018
Adopting GraalVM - Scale by the Bay 2018Adopting GraalVM - Scale by the Bay 2018
Adopting GraalVM - Scale by the Bay 2018
 
Mlocjs buzdin
Mlocjs buzdinMlocjs buzdin
Mlocjs buzdin
 
Web polyglot programming
Web polyglot programmingWeb polyglot programming
Web polyglot programming
 
It pro dev_birbilis_20101127_en
It pro dev_birbilis_20101127_enIt pro dev_birbilis_20101127_en
It pro dev_birbilis_20101127_en
 
Soft-Shake 2016 : Jigsaw est prêt à tuer le classpath
Soft-Shake 2016 : Jigsaw  est prêt à tuer le classpathSoft-Shake 2016 : Jigsaw  est prêt à tuer le classpath
Soft-Shake 2016 : Jigsaw est prêt à tuer le classpath
 
Java 8 Overview
Java 8 OverviewJava 8 Overview
Java 8 Overview
 
Adopting GraalVM - NE Scala 2019
Adopting GraalVM - NE Scala 2019Adopting GraalVM - NE Scala 2019
Adopting GraalVM - NE Scala 2019
 
Javantura v2 - All Together Now - making Groovy and Scala sing together - Din...
Javantura v2 - All Together Now - making Groovy and Scala sing together - Din...Javantura v2 - All Together Now - making Groovy and Scala sing together - Din...
Javantura v2 - All Together Now - making Groovy and Scala sing together - Din...
 
React Native Androidはなぜ動くのか
React Native Androidはなぜ動くのかReact Native Androidはなぜ動くのか
React Native Androidはなぜ動くのか
 
Paug paris 2011
Paug paris 2011Paug paris 2011
Paug paris 2011
 
The curious Life of JavaScript - Talk at SI-SE 2015
The curious Life of JavaScript - Talk at SI-SE 2015The curious Life of JavaScript - Talk at SI-SE 2015
The curious Life of JavaScript - Talk at SI-SE 2015
 
Cleaning your architecture with android architecture components
Cleaning your architecture with android architecture componentsCleaning your architecture with android architecture components
Cleaning your architecture with android architecture components
 
11-DWR-and-JQuery
11-DWR-and-JQuery11-DWR-and-JQuery
11-DWR-and-JQuery
 

Mais de 哲偉 楊 (10)

Specification unit test by Spek
Specification unit test by SpekSpecification unit test by Spek
Specification unit test by Spek
 
Code kata 的自我修煉
Code kata 的自我修煉Code kata 的自我修煉
Code kata 的自我修煉
 
Coding dojo
Coding dojoCoding dojo
Coding dojo
 
輕輕鬆鬆產生 changelog
輕輕鬆鬆產生 changelog輕輕鬆鬆產生 changelog
輕輕鬆鬆產生 changelog
 
Speed up add custom marker on google map
Speed up add custom marker on google mapSpeed up add custom marker on google map
Speed up add custom marker on google map
 
Spek
SpekSpek
Spek
 
Jenkins for android developer at TWJUG
Jenkins for android developer at TWJUGJenkins for android developer at TWJUG
Jenkins for android developer at TWJUG
 
自己的 Jenkins 自己來 for Android developer
自己的 Jenkins 自己來  for Android developer自己的 Jenkins 自己來  for Android developer
自己的 Jenkins 自己來 for Android developer
 
從開發到上線的華麗大冒險
從開發到上線的華麗大冒險從開發到上線的華麗大冒險
從開發到上線的華麗大冒險
 
Kotlin初體驗
Kotlin初體驗Kotlin初體驗
Kotlin初體驗
 

Último

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Último (20)

[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 

RxJava With retrolambda