SlideShare uma empresa Scribd logo
1 de 22
Baixar para ler offline
Event Bus
Android Simplificado
Componentes Android
Activity Service
Fragment Fragment Custom View
Comunicação Android
Activity Service
Fragment Fragment Custom View
Delegate Android
Activity
ServiceFragment
Fragment Custom View
Activity se torna God Object
Activity precisa implementar diversas interfaces
Excesso de cast e instance of
class GodActivity implements A, B, C, D, E, Fuck {}
Delegate :( Android
Publish / Subscribe Papéis
Publisher
Event
Bus
SubscriberEvent Event
Event Bus Android
ServiceFragment
Fragment Custom View
Event
Bus
Activity
EventBus by greenrobot
EventBus
// Create a bus
EventBus bus = new EventBus();
// Or use the default
EventBus bus = EventBus.getDefault();
// Publish
bus.post(new AnyEvent());
https://github.com/greenrobot/EventBus
// Register - onCreate, onStart
bus.register(this);
// Unregister - onDestroy, onStop
bus.unregister(this);
public void onEvent(AnyEvent e) {
[...]
}
public void onEventMainThread(AnyEvent e) {}
EventBus https://github.com/greenrobot/EventBus
// Sticky Publish
bus.postSticky(new AnyEvent());
// Sticky Register
bus.registerSticky(this);
EventBus https://github.com/greenrobot/EventBus
Otto by Square
// Create a main thread bus
Bus bus = new Bus();
// Create an any thread bus
Bus bus = new Bus(ThreadEnforcer.ANY);
// Publish
bus.post(new AnyEvent());
Otto https://square.github.io/otto/
Otto
// Register - onCreate, onStart
bus.register(this);
// Unregister - onDestroy, onStop
bus.unregister(this);
@Subscribe
public void onAnyEvent(AnyEvent e) {
[...]
}
https://square.github.io/otto/
Otto
@Subscribe
public void onAnyEvent(AnyEvent e) {
[...]
}
@Produce
public AnyEvent produceAnyEvent() {
return AnyEvent.getLast();
}
https://square.github.io/otto/
Via Reflection
Fornece um Bus Default
Valor Anterior via *Sticky
Threading feita no Evento
OttoEventBus
Via Annotation
Gerenciamento Manual de Bus
Valor Inicial via @Produce
Threading feita no Bus
Caso de uso
Activity
Fragment
Custom View
Fragment
Crie Suvinil https://play.google.com/store/apps/details?id=com.basf.suvinil.crie
420 LOC
0 Interfaces
Eventos organizados
Delegate EventBus
750+ LOC
9 Interfaces
Interfaces fragmentadas
Referências
Google Developer Experts
https://medium.com/google-developer-experts/
Event-driven programming for Android (part I)
https://medium.com/google-developer-experts/event-driven-programming-for-android-part-i-f5ea4a3c4eab
Event-driven programming for Android (part II)
https://medium.com/google-developer-experts/event-driven-programming-for-android-part-ii-b1e05698e440
Event-driven programming for Android (part III)
Em breve...
@mickele@ademar111190

Mais conteúdo relacionado

Destaque

Presentació corporativa 2013
Presentació corporativa 2013Presentació corporativa 2013
Presentació corporativa 2013
TMB
 
PRACTICA SOBRE REFERENCIA A CELDAS, ABSOLUTAS Y RELATIVAS
PRACTICA SOBRE REFERENCIA A CELDAS, ABSOLUTAS Y RELATIVASPRACTICA SOBRE REFERENCIA A CELDAS, ABSOLUTAS Y RELATIVAS
PRACTICA SOBRE REFERENCIA A CELDAS, ABSOLUTAS Y RELATIVAS
Jessica Paola
 
Medios de transporte
Medios de transporteMedios de transporte
Medios de transporte
analu-08
 
REFERNCIAS A CELDA * REFERENCIAS ABSOLUTAS Y RELATIVAS
REFERNCIAS A CELDA * REFERENCIAS ABSOLUTAS Y RELATIVASREFERNCIAS A CELDA * REFERENCIAS ABSOLUTAS Y RELATIVAS
REFERNCIAS A CELDA * REFERENCIAS ABSOLUTAS Y RELATIVAS
Andreita Aguilar
 
El transporte cristian
El  transporte cristianEl  transporte cristian
El transporte cristian
nosecristian
 

Destaque (20)

Daten verknüpfen - Geschäftsprozesse organisieren: der ExsoFlow-Server
Daten verknüpfen - Geschäftsprozesse organisieren: der ExsoFlow-ServerDaten verknüpfen - Geschäftsprozesse organisieren: der ExsoFlow-Server
Daten verknüpfen - Geschäftsprozesse organisieren: der ExsoFlow-Server
 
Referencias relativas
Referencias relativasReferencias relativas
Referencias relativas
 
Presentació corporativa 2013
Presentació corporativa 2013Presentació corporativa 2013
Presentació corporativa 2013
 
PRACTICA SOBRE REFERENCIA A CELDAS, ABSOLUTAS Y RELATIVAS
PRACTICA SOBRE REFERENCIA A CELDAS, ABSOLUTAS Y RELATIVASPRACTICA SOBRE REFERENCIA A CELDAS, ABSOLUTAS Y RELATIVAS
PRACTICA SOBRE REFERENCIA A CELDAS, ABSOLUTAS Y RELATIVAS
 
ShareMyBook: As 5 telas e suas Interfaces
ShareMyBook: As 5 telas e suas InterfacesShareMyBook: As 5 telas e suas Interfaces
ShareMyBook: As 5 telas e suas Interfaces
 
Stqbus, app busos sant cugat
Stqbus, app busos sant cugatStqbus, app busos sant cugat
Stqbus, app busos sant cugat
 
Le voyage
Le voyageLe voyage
Le voyage
 
Medios de transporte
Medios de transporteMedios de transporte
Medios de transporte
 
Ss3 my city
Ss3 my citySs3 my city
Ss3 my city
 
REFERNCIAS A CELDA * REFERENCIAS ABSOLUTAS Y RELATIVAS
REFERNCIAS A CELDA * REFERENCIAS ABSOLUTAS Y RELATIVASREFERNCIAS A CELDA * REFERENCIAS ABSOLUTAS Y RELATIVAS
REFERNCIAS A CELDA * REFERENCIAS ABSOLUTAS Y RELATIVAS
 
El transporte cristian
El  transporte cristianEl  transporte cristian
El transporte cristian
 
Flashcards
FlashcardsFlashcards
Flashcards
 
Les vacances des allemands
Les vacances des allemandsLes vacances des allemands
Les vacances des allemands
 
Promotionbus
PromotionbusPromotionbus
Promotionbus
 
Consulta diagonal 2010
Consulta diagonal 2010Consulta diagonal 2010
Consulta diagonal 2010
 
Vueltaalmundo
VueltaalmundoVueltaalmundo
Vueltaalmundo
 
Propostes veïns
Propostes veïnsPropostes veïns
Propostes veïns
 
Katia
KatiaKatia
Katia
 
#RecuperemBlanes: "Menys zones blaves, més transport públic!"
#RecuperemBlanes: "Menys zones blaves, més transport públic!"#RecuperemBlanes: "Menys zones blaves, més transport públic!"
#RecuperemBlanes: "Menys zones blaves, més transport públic!"
 
Infraestructura i finançament
Infraestructura i finançamentInfraestructura i finançament
Infraestructura i finançament
 

Semelhante a Event Bus: Android Simplificado

The Open Web and what it means
The Open Web and what it meansThe Open Web and what it means
The Open Web and what it means
Robert Nyman
 
Android app development basics
Android app development basicsAndroid app development basics
Android app development basics
Anton Narusberg
 

Semelhante a Event Bus: Android Simplificado (20)

Event Bus by Gokhan Arik - Dalvik Android Talks at CRi
Event Bus by Gokhan Arik - Dalvik Android Talks at CRiEvent Bus by Gokhan Arik - Dalvik Android Talks at CRi
Event Bus by Gokhan Arik - Dalvik Android Talks at CRi
 
EventBus for Android
EventBus for AndroidEventBus for Android
EventBus for Android
 
Google Web Toolkits
Google Web ToolkitsGoogle Web Toolkits
Google Web Toolkits
 
The 2016 Android Developer Toolbox [MOBILIZATION]
The 2016 Android Developer Toolbox [MOBILIZATION]The 2016 Android Developer Toolbox [MOBILIZATION]
The 2016 Android Developer Toolbox [MOBILIZATION]
 
The Open Web and what it means
The Open Web and what it meansThe Open Web and what it means
The Open Web and what it means
 
Geb presentation
Geb presentationGeb presentation
Geb presentation
 
Getting Ready For Android Wear
Getting Ready For Android WearGetting Ready For Android Wear
Getting Ready For Android Wear
 
DWR, Hibernate and Dojo.E - A Tutorial
DWR, Hibernate and Dojo.E - A TutorialDWR, Hibernate and Dojo.E - A Tutorial
DWR, Hibernate and Dojo.E - A Tutorial
 
Gdg san diego android 11 meetups what's new in android - ui and dev tools
Gdg san diego android 11 meetups  what's new in android  - ui and dev toolsGdg san diego android 11 meetups  what's new in android  - ui and dev tools
Gdg san diego android 11 meetups what's new in android - ui and dev tools
 
How to code to code less
How to code to code lessHow to code to code less
How to code to code less
 
Dicoding Developer Coaching #30: Android | Mengenal Macam-Macam Software Desi...
Dicoding Developer Coaching #30: Android | Mengenal Macam-Macam Software Desi...Dicoding Developer Coaching #30: Android | Mengenal Macam-Macam Software Desi...
Dicoding Developer Coaching #30: Android | Mengenal Macam-Macam Software Desi...
 
Developing Android and iOS Apps With C#, .NET, Xamarin, Mono, and Windows Azure
Developing Android and iOS Apps With C#, .NET, Xamarin, Mono, and Windows AzureDeveloping Android and iOS Apps With C#, .NET, Xamarin, Mono, and Windows Azure
Developing Android and iOS Apps With C#, .NET, Xamarin, Mono, and Windows Azure
 
The 2016 Android Developer Toolbox [NANTES]
The 2016 Android Developer Toolbox [NANTES]The 2016 Android Developer Toolbox [NANTES]
The 2016 Android Developer Toolbox [NANTES]
 
Google Web Toolkits
Google Web ToolkitsGoogle Web Toolkits
Google Web Toolkits
 
React native by example by Vadim Ruban
React native by example by Vadim RubanReact native by example by Vadim Ruban
React native by example by Vadim Ruban
 
Android app development basics
Android app development basicsAndroid app development basics
Android app development basics
 
Build pipelines with TeamCity and Kotlin DSL
Build pipelines with TeamCity and Kotlin DSLBuild pipelines with TeamCity and Kotlin DSL
Build pipelines with TeamCity and Kotlin DSL
 
Learning Android Part 2/6
Learning Android Part 2/6Learning Android Part 2/6
Learning Android Part 2/6
 
Building an Android app with Jetpack Compose and Firebase
Building an Android app with Jetpack Compose and FirebaseBuilding an Android app with Jetpack Compose and Firebase
Building an Android app with Jetpack Compose and Firebase
 
io 19 extended android flutter&mlkit
io 19 extended android flutter&mlkitio 19 extended android flutter&mlkit
io 19 extended android flutter&mlkit
 

Último

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
+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@
 

Último (20)

Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
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
 
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
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
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
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
+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...
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 

Event Bus: Android Simplificado