I have been using the SingleLiveData
class which can be found here. My questions are:
Is SingleLiveData
is actually part of the Android Architecture Components?
Is it a good idea to use it?
SingleLiveEvent:- SingleLiveEvent is a subclass of MutableLiveData with a single Observer Observing it at a time, hence it is aware of view's lifecycle.
Add SingleLiveEvent class in your code: SingleLiveEvent is not yet part of Android Architecture Lifecycle Component library and you'll have to include it in your code. Make a class name SingleLiveEvent. java and paste this code in it. After this we will create a sealed class called BaseCommand.
LiveData is an observable data holder class. Unlike a regular observable, LiveData is lifecycle-aware, meaning it respects the lifecycle of other app components, such as activities, fragments, or services. This awareness ensures LiveData only updates app component observers that are in an active lifecycle state.
Is SingleLiveEvent actually part of the Android Architecture Components Library?
No, and it won't be: https://issuetracker.google.com/issues/122413110. Basically, the official answer is "Yes, regular livedata wasn't enough, so we introduced it in our examples but it's too hacky to be in the library".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With