-2

Ok I get the concept, but I’m a bit confused, the mutableLiveData gives you access to the set and Post method, which you use to add Values to your live data, it then calls the onChanged method of the observer, why don’t we just use LiveData instead, instead of setting the value, we call the repository to update the list in the database, isn’t that a bit safer??

1 Answers1

0

In an app with a repository that provides a LiveData view of some piece of data, you absolutely should make your updates through that repository. In that case, the repository (or the database layer it uses, like Room) manages holding and setting the value of the MutableLiveData for you. You should only be setting the values on MutableLiveData when you are the owner/provider of that data.

Ryan M
  • 18,333
  • 31
  • 67
  • 74
  • ok so that means to the remaining layers it should be LiveData, but somewhere in the repository or the Database actually , it should use MutableLiveData to add the Value to our list of objects? – Chukwudi Ogbonna May 05 '20 at 00:10
  • @ChukwudiOgbonna Yep! Exactly right. – Ryan M May 05 '20 at 00:11