I'm unable to distinguish what to use. It seems are all working in a same way but different way but the base logic are same, kindly let me know what is the main difference in all?
EventBus
is just some kind of tool that has been written with Observer-like situations in mind. The general usage of EventBus
is to fire events so we can use of the word Observer to fit for it. Observer pattern uses events or messages to notify of a change to objects of interest about the object being observed(changed).
And EventBus
is also not observer pattern because if you have N objects and you want to communicate between all of them you need N*N observers if you use the observer pattern but only one global EventBus
is enough to do the same job.
So EventBus
is the EventBus-pattern.
And LiveData
is also considered as an observable data holder class that used in Observer pattern. Unlike a regular observable, LiveData
is lifecycle-aware, meaning it respects the lifecycle of other app components, such as activities, fragments, or services.
So LiveData
is the Observer pattern for Android, or can be considered the separate LiveData-pattern.