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 GodActiv...
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();
// Pub...
// Register - onCreate, onStart
bus.register(this);
// Unregister - onDestroy, onStop
bus.unregister(this);
public void on...
// Sticky Publish
bus.postSticky(new AnyEvent());
// Sticky Register
bus.registerSticky(this);
EventBus https://github.com...
Otto by Square
// Create a main thread bus
Bus bus = new Bus();
// Create an any thread bus
Bus bus = new Bus(ThreadEnforcer.ANY);
// Pub...
Otto
// Register - onCreate, onStart
bus.register(this);
// Unregister - onDestroy, onStop
bus.unregister(this);
@Subscrib...
Otto
@Subscribe
public void onAnyEvent(AnyEvent e) {
[...]
}
@Produce
public AnyEvent produceAnyEvent() {
return AnyEvent....
Via Reflection
Fornece um Bus Default
Valor Anterior via *Sticky
Threading feita no Evento
OttoEventBus
Via Annotation
Ger...
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 (pa...
@mickele@ademar111190
Event Bus: Android Simplificado
Próximos SlideShares
Carregando em…5
×

Event Bus: Android Simplificado

873 visualizações

Publicada em

Como simplificar o desenvolvimento melhorando a comunicação entre componentes Android.

Publicada em: Tecnologia
0 comentários
2 gostaram
Estatísticas
Notas
  • Seja o primeiro a comentar

Sem downloads
Visualizações
Visualizações totais
873
No SlideShare
0
A partir de incorporações
0
Número de incorporações
7
Ações
Compartilhamentos
0
Downloads
6
Comentários
0
Gostaram
2
Incorporações 0
Nenhuma incorporação

Nenhuma nota no slide

Event Bus: Android Simplificado

  1. 1. Event Bus Android Simplificado
  2. 2. Componentes Android Activity Service Fragment Fragment Custom View
  3. 3. Comunicação Android Activity Service Fragment Fragment Custom View
  4. 4. Delegate Android Activity ServiceFragment Fragment Custom View
  5. 5. 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
  6. 6. Publish / Subscribe Papéis Publisher Event Bus SubscriberEvent Event
  7. 7. Event Bus Android ServiceFragment Fragment Custom View Event Bus Activity
  8. 8. EventBus by greenrobot
  9. 9. 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
  10. 10. // 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
  11. 11. // Sticky Publish bus.postSticky(new AnyEvent()); // Sticky Register bus.registerSticky(this); EventBus https://github.com/greenrobot/EventBus
  12. 12. Otto by Square
  13. 13. // 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/
  14. 14. Otto // Register - onCreate, onStart bus.register(this); // Unregister - onDestroy, onStop bus.unregister(this); @Subscribe public void onAnyEvent(AnyEvent e) { [...] } https://square.github.io/otto/
  15. 15. Otto @Subscribe public void onAnyEvent(AnyEvent e) { [...] } @Produce public AnyEvent produceAnyEvent() { return AnyEvent.getLast(); } https://square.github.io/otto/
  16. 16. 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
  17. 17. Caso de uso Activity Fragment Custom View Fragment
  18. 18. Crie Suvinil https://play.google.com/store/apps/details?id=com.basf.suvinil.crie
  19. 19. 420 LOC 0 Interfaces Eventos organizados Delegate EventBus 750+ LOC 9 Interfaces Interfaces fragmentadas
  20. 20. 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...
  21. 21. @mickele@ademar111190

×