Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is SingleLiveEvent actually part of the Android Architecture Components Library?

Tags:

I have been using the SingleLiveData class which can be found here. My questions are:

  1. Is SingleLiveData is actually part of the Android Architecture Components?

  2. Is it a good idea to use it?

like image 377
Archie G. Quiñones Avatar asked Aug 10 '18 07:08

Archie G. Quiñones


People also ask

What is Android SingleLiveEvent?

SingleLiveEvent:- SingleLiveEvent is a subclass of MutableLiveData with a single Observer Observing it at a time, hence it is aware of view's lifecycle.

How do I import SingleLiveEvent?

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.

What is live data in Android?

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.


1 Answers

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".

like image 190
Ghedeon Avatar answered Oct 27 '22 00:10

Ghedeon