infinum android talks #02 - eventbus
DESCRIPTION
Need an efficient way to communicate between different parts of the app? Enter - EventBus.TRANSCRIPT
![Page 1: Infinum Android Talks #02 - EventBus](https://reader033.vdocuments.us/reader033/viewer/2022042713/54892efeb479590f0d8b580b/html5/thumbnails/1.jpg)
EventBus Dino Kovač
![Page 2: Infinum Android Talks #02 - EventBus](https://reader033.vdocuments.us/reader033/viewer/2022042713/54892efeb479590f0d8b580b/html5/thumbnails/2.jpg)
• 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](https://reader033.vdocuments.us/reader033/viewer/2022042713/54892efeb479590f0d8b580b/html5/thumbnails/3.jpg)
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](https://reader033.vdocuments.us/reader033/viewer/2022042713/54892efeb479590f0d8b580b/html5/thumbnails/4.jpg)
• 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](https://reader033.vdocuments.us/reader033/viewer/2022042713/54892efeb479590f0d8b580b/html5/thumbnails/5.jpg)
Register for events
![Page 6: Infinum Android Talks #02 - EventBus](https://reader033.vdocuments.us/reader033/viewer/2022042713/54892efeb479590f0d8b580b/html5/thumbnails/6.jpg)
Post events
![Page 7: Infinum Android Talks #02 - EventBus](https://reader033.vdocuments.us/reader033/viewer/2022042713/54892efeb479590f0d8b580b/html5/thumbnails/7.jpg)
Handle events
![Page 8: Infinum Android Talks #02 - EventBus](https://reader033.vdocuments.us/reader033/viewer/2022042713/54892efeb479590f0d8b580b/html5/thumbnails/8.jpg)
Threads, Crouton
![Page 9: Infinum Android Talks #02 - EventBus](https://reader033.vdocuments.us/reader033/viewer/2022042713/54892efeb479590f0d8b580b/html5/thumbnails/9.jpg)
• 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://reader033.vdocuments.us/reader033/viewer/2022042713/54892efeb479590f0d8b580b/html5/thumbnails/10.jpg)
https://github.com/greenrobot/EventBus !
https://github.com/keyboardsurfer/Crouton !
https://github.com/reisub/eventbus-example
Links