Android Jetpack: LiveData

Android Developers · 105K views · 2018 · 5:30

Open on YouTube

Software (other)Software architecture & designexplainerdated

Why Stack Overflow recommends it

Stack Overflow users link it as a quick explanation of what LiveData is and how it connects Room, ViewModel and data binding to the UI.

Recommended by 1 people across 1 different months, 2019 to 2020.

What it is

A short official Android Developers video introducing LiveData, the lifecycle-aware observable from the Jetpack Lifecycle library. It covers how LiveData keeps the UI in sync with data, works with ViewModel, Room and Data Binding, and includes basic transformations like map and switchMap.

What people said

Recommends Domino · 2020-06 · Stack Overflow · on “Synchronize RecyclerView data between two devices?”

The thing you are looking for is LiveData. There are really nice tutorials from Android Jetpack team: How to connect Room with RxJava (e.g. LiveData): [LINK] LiveData explained: [this video] Code examples: [LINK]

Cites C. MARTIN · 2019-07 · Stack Overflow · on “How to databind livedata object (android)”

Today I've some question about mvvm and databinding on android, I'm trying to bind object properties on view. I've an Object (Model) with some properties, by example : public String name; public String title; public int value; I've a ViewModel with livedata like this : MutableLiveData<Object> _obj = new MutableLiveData<>(); public LiveData<Object> obj = _obj; And, at last, I've a view like this : <layout> <data> <variable name="viewModel"> type="com.sample.app.viewmodels.MainViewModel" /> </data> <LinearLayout ... > <TextView android:text:="@{viewModel.obj.name}" .../> </LinearLayout> </layout> I saw that we can do that in a video from "Android Developers" about "LiveData" : [this video] She says

Cites Lyla · 2019-08 · Stack Overflow · on “How to refresh the UI of a fragment using LiveData after Firestore data loads”

When troubleshooting this issue, I'd recommend starting by looking at two things. Take a look at where/when you're updating your LiveData The goal is whenever the data in Firebase updates, your assignments LiveData updates your UI. Something like: Firestore updates Firestore triggers SnapshotListener SnapshotListener updates LiveData LiveData observer updates UI So in your snapshot listener, you should be updating your LiveData, which is what I think you're missing. So it would be something like: // Where you define your SnapshotListner assignmentQuery.addSnapshotListener { documents, _ -> // Process the data documents?.forEach { document -> val a = document.toObject(AssignmentModel::class.j