Possible to access AndroidViewModel of Activity via Fragment?
问题 In the summer of last year I started refactoring my Android application with Android's architecture components (Room, ViewModel, LiveData). I have two Room repositories, one of them is accessed by multiple views (fragments) of the application. Because of that I used an AndroidViewModel , which has access to this repository and which is initialized in my MainActivity . new ViewModelProvider(this).get(CanteensViewModel.class); In my two fragments I accessed this ViewModel by new