Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Event Bus: Android Simplificado

Event Bus: Android Simplificado

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

# Libs

EventBus
https://github.com/greenrobot/EventBus

Otto
https://square.github.io/otto/

# Referências

Google Developer Experts
https://medium.com/google-developer-experts/

# Autores

Mickele Moriconi
https://twitter.com/mickele

Ademar Oliveira
https://twitter.com/ademar111190

Mickele Moriconi

February 03, 2015
Tweet

More Decks by Mickele Moriconi

Other Decks in Programming

Transcript

  1. 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
  2. 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
  3. // 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
  4. // 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/
  5. Otto // Register - onCreate, onStart bus.register(this); // Unregister -

    onDestroy, onStop bus.unregister(this); @Subscribe public void onAnyEvent(AnyEvent e) { [...] } https://square.github.io/otto/
  6. Otto @Subscribe public void onAnyEvent(AnyEvent e) { [...] } @Produce

    public AnyEvent produceAnyEvent() { return AnyEvent.getLast(); } https://square.github.io/otto/
  7. Via Reflection Fornece um Bus Default Valor Anterior via *Sticky

    Threading feita no Evento Otto EventBus Via Annotation Gerenciamento Manual de Bus Valor Inicial via @Produce Threading feita no Bus
  8. 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) https://medium.com/google-developer-experts/event-driven-programming-for-android-part-iii-3a2e68c3faa4