Upload
infinum-ltd
View
767
Download
2
Embed Size (px)
DESCRIPTION
Need an efficient way to communicate between different parts of the app? Enter - EventBus.
Citation preview
EventBus Dino Kovač
• simple communication between parts of the app
• avoid spaghetti code • easy way to notify the user when
he loses network connectivity
Motivation
Init
• add a maven dependency or add as a jar • … and you’re done :)
compile ‘de.greenrobot:eventbus:2.2.0@jar’
• register subscribers
•EventBus.getDefault().register(object); !• post events
•EventBus.getDefault().post(new Object()); !• handle events in onEvent methods
•public void onEvent(Object o) { … }
Usage
Register for events
Post events
Handle events
Threads, Crouton
• sticky events • registerSticky(object); postSticky(new Object());
!• async event delivery
• onEventAsync(Object o) { … } !• multiple EventBus buses
You need more?
https://github.com/greenrobot/EventBus !
https://github.com/keyboardsurfer/Crouton !
https://github.com/reisub/eventbus-example
Links