I have situation here , Live data Observer is set ...
# android
c
I have situation here , Live data Observer is set on database object to collect some stack of cards , These stack of cards is shown sequentially to user for every 2 minutes . once this card is shown , I will have to update database to modify its status . but you know how the live data work with room, every time you make update specific row, live data will retrigger (you can read here) , that will call whole flow once again which needs to be avoided To avoid this re-triggering , I made some modification, I will collect cards at the initial, and soon after that I will remove observer My code looks as below
Copy code
observer = Observer<Resource<List<DisplayCard>>> {
    when (it.status) {
        Status.SUCCESS -> {
            // setting list to emit card for every 2 minutes once
            ambientDisplayViewModel.setListOfCards(it.data ?: emptyList())
            // removing observer
            ambientDisplayViewModel.ambientCardList.removeObservers(viewLifecycleOwner)
        }
        Status.LOADING -> {
        }

        Status.ERROR -> {
            ambientDisplayViewModel.refresh(DataSource(loadFromNetwork = false))
        }
    }

}
With above code , I have received review comments from my peer as below "Viewmodel callback should come to activity/fragment only when there's an intention to update the view." , Do you agree on this quote ? Do you think that I shouldn't keep callback when I am not making any UI
😶 3