Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EventBus use, memory and architecture

I'm starting using EventBus in my app and it's really nice to use, it solve a lot of problems and simplify the code, and the propagation all over the app with all threads and everything is fantastic, but I'm feeling I maybe abusing of the use of events.

For now everything is fine, I'm testing in powerful devices and the app response is really nice, but I have a lot of coding to do yet and I'm starting to question myself how will affect having too much events triggering all over the app.

So the question is for anyone that have experience with that library if there is some problems with having a lot of events in my app, if there is some known memory issues related to the use of this events. I'm trying to use it wisely, but it's difficult not to include it a lot in your architecture because it's a really nice functionality. Anyway if you have something to say about the subject will be nice because I have a lot of coding to do and will be a problem have my architecture wrong and have to go back to make changes because some issues related to the events.

PD. I'm talking about native Android app, with a lot of networking

Thx

like image 420
labreu Avatar asked Oct 28 '14 17:10

labreu


1 Answers

It's not a problem having many events in your app as long as you follow components lifecycle changes: register for events in onStart() and unregister in onStop(). If you do this, then only a relatively small subset of active components will be subscribed for events, which makes whole solution lean.

In my app I had some issue with the central singleton event bus instance, that's why I use a lightweight and fast event bus capable to attach to an activity and respect it's lifecycle. With it I can have a bus instance per activity, which is very lightweight.

like image 131
sergej shafarenka Avatar answered Sep 17 '22 12:09

sergej shafarenka