Kulwinder Singh
12/11/2019, 4:23 AMonActive
is called immedietly but it won't update value
of live data until suspending
task inside other ViewModel
finished
class DocumentLiveData<T>(
private val documentReference: DocumentReference,
private val typeClass: Class<T>
) : LiveData<T>() {
override fun onActive() {
super.onActive()
listener = documentReference.addSnapshotListener(changes) { documentSnapshot, exception ->
//this listener is called but `value` is not updated immedietly
if (exception == null && documentSnapshot?.exists() == true) {
value = documentSnapshot.toObject(typeClass)
} else {
value = null
}
}
}
}
rkeazor
12/11/2019, 12:46 PMKulwinder Singh
12/12/2019, 5:49 AMmyLeaderboard
inside MainActivity then it works immediately but if i observe it inside child fragment then it works with delay