The problem is that this myLiveData = repository. getAllTransactions()
part is done When you create instance of viewmodel.
Before you start to observe myLiveData
the query result has been posted.
What you should do is to make a method in ViewModel
fun getAllTransactions():LiveData<List<MyTransaction>> {
return repository. getAllTransactions();
}
And in the activity,
mViewModel!!.getAllTransactions().observe(this, Observer<List< MyTransaction >> { repositories: List< MyTransaction > ->
//your code goes here
})
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…