Using EventBus, memory and architecture

I am starting to use EventBus in my application, and it is very nice to use it, it solves many problems and simplifies the code, and the distribution throughout the application with all the streams is just fantastic, but I feel I may abuse the use of events.

At the moment, everything is in order, I'm testing on powerful devices, and the application response is really nice, but I still have a lot of coding, and I begin to doubt how it will affect too many events that run throughout the application.

So, the question is for those who have experience with this library if there are some problems with the presence of a large number of events in my application, if there are some known memory problems associated with the use of these events. I'm trying to use it wisely, but it's hard not to include it in your architecture because it is really good functionality. In any case, if you have something to say about the subject, it will be good, because I have a lot of coding, and the problem will have the wrong architecture and come back to changes, because some problems are related to events.

PD. I'm talking about a native Android app with lots of networks

thanks

+5
source share
2 answers

This is not a problem with many events in your application, if you follow the changes in the component life cycle: register for events in onStart() and unregister in onStop() . If you do this, then only a relatively small subset of the active components will be signed for the events, which will complicate the solution as a whole.

In my application, I had a problem with the central instance of the Singleton bus, so I use a lightweight and fast event bus that can connect to the activity and respect its life cycle. With it, I can have a bus instance for an activity that is very light.

+4
source

I understand what you are saying, and I am also working on a rather massive code base in our company, and we often use the event bus. You just have to be careful with it, but it can be annoying to find out which places in the application are subscribed to a specific event. If there are several signatures, then you have to fish through the application, this is not very fun. As a solution to this, I love to use this wonderful Android Studio plug-in for Otto Event Bus, which will easily get you and events to your subscribers or vice versa.

https://github.com/square/otto-intellij-plugin

This will really help simplify navigation between events and subscribers.

+2
source

Source: https://habr.com/ru/post/1205718/


All Articles