Reputation: 503
Can I (is it correct to) use an event bus to communicate between UI views? For exemple, use it to communicate between Fragments instead of implementing a listener?
Can I use the same instance of the bus for more than one operation?
Thank you
Upvotes: 2
Views: 635
Reputation: 1178
Yes.
Otto was built exactly for that reason: to help you communicate fragments
and activities
aside without the need of serializing everything through Intent
s.
Also, for the instance question: You can reuse the bus wherever you want to. Sometimes, though, you would prefer to create different buses to separate groups of classes communicating: for example, in an MVP architecture, you would have a bus for each M-V-P group, or in another example, a bus for communicating with a specific service that is always running, etc.
This is a good example on how to use the library.
Upvotes: 4