Is it possible to prevent LiveData
receive the last value when start observing?
I am considering to use LiveData
as events.
For example events like show message, a navigation event or a dialog trigger, similar to EventBus
.
The problem related to communication between ViewModel
and fragment, Google gave us LiveData
to update the view with data, but this type of communication not suitable when we need update the view only once with single event, also we cannot hold view's reference in ViewModel
and call some methods because it will create memory leak.
I found something similar SingleLiveEvent - but it work only for 1 observer and not for multiple observers.
--- Update ----
As @EpicPandaForce said "There is no reason to use LiveData as something that it is not", probably the intent of the question was Communication between view and ViewModel in MVVM with LiveData
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…