發表文章

目前顯示的是 2月 28, 2019的文章

Android, Do I use ViewModel to perform insertion or update?

圖片
1 I understand that ViewModel in the Architecture component is for storage and managing data so it will not be lost during config changes. For example, my activity has nothing do with LiveData or using storage Data. Should I still go through ViewModel? or directly instantiate the Repo Class and call the insertion method? I hope that make sense An Example of my usage of ViewModel public class MainViewModel extends AndroidViewModel { private DataRepo dataRepo; private LiveData<List<Group>> groupList; private LiveData<List<Bill>> billList; public MainViewModel(Application application) { super(application); dataRepo = new DataRepo(this.getApplication)); groupList = dataRepo.getGroup(); billList = dataRepo.getBill(); } publ