Hi all, Looking into LiveData ViewModel and Data...
# android
b
Hi all, Looking into LiveData ViewModel and Data DAOs and Repositories. I understand you would link a ViewModel with an Activity and thus the data is linked to Views in the Activities View. But how do you link a ViewModel to the Application. Like a User Data, which is needed by multiple Activities. Thus holding one copy of the LiveData for the entire Application. Thanks
😶 2
j
Actually no. You don't need to link a viewmodel with an activity. Viewmodel doesn't know nothing about activities/fragments. It just exposes livedatas and methods to be used by any view that wants to observe them. So probably what you need is to store that data in a repository or DAO and when your activity/view needs that data, the viewmodel will expose it by calling the necessary repositories/daos. Finally, the views will react to these changes.