Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Event Bus Register And Unregister in Application Class

Should i register and unregister the event bus in application class? If yes then where should i register and unregister it?

Once Register of event bus is done in application class then should i need to register the event bus in suscriber class?

Is there any problem occurs if i put some methods in Application class as a suscriber methods?

like image 964
sanil Avatar asked Oct 17 '25 22:10

sanil


1 Answers

No one, except you, can tell whether you should or shouldn't register Application as a listener on EventBus - it depends on your app's use cases.

If the event is relevant to a specific Activity/Fragment/Service - register them as listeners.

If the event is relevant in the "global" sense (i.e. centralized error handling based on events) - you might register Application as listener.

You don't need to unregister Application from EventBus in order to prevent memory leaks because:

  • their lyfe-cycles are identical (Application can be treated as Singleton object)
  • there is no onDestroy() method in Application
like image 197
Vasiliy Avatar answered Oct 20 '25 13:10

Vasiliy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!