I've been searching for the best approach to using Shared Preferences in MVVM architecture in Android but I could just find pieces and thus having no clear image over ho to do it in the best way. Therefore I have a few questions:
- Should I keep a singleton instance of a SharedPrefs over the app?
- Should ViewModel and Repository use Shared Preferences?
- Where to use them? Let's say there is a Fragment, a ViewModel and a Repository. Should I control the SharedPrefs from ViewModel for Fragment and Repository or should each one take care on their own? E.g. User clicks on a button to save a setting. Save in SP from fragment? Make a call to a method from ViewModel to save in SP? Or redirect further to Reposioty to use SP?
(*SP = Shared Preferences)
I would really appreciate to get some advice for the best practice of SharePreferences in MVVM Android