10
EventBus Dino Kovač

Infinum Android Talks #02 - EventBus

Embed Size (px)

DESCRIPTION

Need an efficient way to communicate between different parts of the app? Enter - EventBus.

Citation preview

Page 1: Infinum Android Talks #02 - EventBus

EventBus Dino Kovač

Page 2: Infinum Android Talks #02 - EventBus

• simple communication between parts of the app

• avoid spaghetti code • easy way to notify the user when

he loses network connectivity

Motivation

Page 3: Infinum Android Talks #02 - EventBus

Init

• add a maven dependency or add as a jar • … and you’re done :)

compile ‘de.greenrobot:eventbus:2.2.0@jar’

Page 4: Infinum Android Talks #02 - EventBus

• register subscribers

•EventBus.getDefault().register(object); !• post events

•EventBus.getDefault().post(new Object()); !• handle events in onEvent methods

•public void onEvent(Object o) { … }

Usage

Page 5: Infinum Android Talks #02 - EventBus

Register for events

Page 6: Infinum Android Talks #02 - EventBus

Post events

Page 7: Infinum Android Talks #02 - EventBus

Handle events

Page 8: Infinum Android Talks #02 - EventBus

Threads, Crouton

Page 9: Infinum Android Talks #02 - EventBus

• sticky events • registerSticky(object); postSticky(new Object());

!• async event delivery

• onEventAsync(Object o) { … } !• multiple EventBus buses

You need more?

Page 10: Infinum Android Talks #02 - EventBus

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

https://github.com/keyboardsurfer/Crouton !

https://github.com/reisub/eventbus-example

Links