Ian Lake
Ian Lake
Jul 29, 2017 · 1 min read

I think the most important thing is to have a single source of truth. In these first examples, our source of truth was a json file and the LiveData was the only thing reading that file. What we didn’t cover was what writes to that file.

As per the Guide to App Architecture, it is generally the responsibility of a separate repository object that would be managing that json file, both in terms of controlling writing to it and in providing the LiveData object that would receive a callback whenever the underlying data changes.

Therefore it makes the most sense if it is that repository object that has your refresh method (that you’d then expose to your UI layer via a method in your ViewModel so as to not tightly couple the repository and UI) and expose refresh status (if needed). This approach is covered in the Persisting data section and the Addendum: exposing network status.

Of course, like all architecture patterns, there’s a lot of flexibility and you shouldn’t over complicate something unless it gives you a tangible benefit (such as increased testability or easier reuse across your app). Just be aware of the trade offs you are making.

    Ian Lake

    Written by

    Ian Lake

    Android Framework Developer at Google and Runner www.google.com/+IanLake