architecture-components-samples
architecture-components-samples copied to clipboard
How ViewModel communicate with other ViewModel that in the same Activity?
Helllo dev:
How ViewModel communicate with other ViewModel that in the same Activity?
Could you provide some suggest or sample? Thanks.
Because i have a similar "Master/Detail Fragment" that has "MasterViewModel and DetailViewModel", so i want to reuse them when the device switches between portrait and landscape orientation.
Issue below not my love: https://github.com/googlesamples/android-architecture-components/issues/109
Use a shared ViewModel which provides data for both the MasterFragment and DetailFragment. Initialize the ViewModel in both fragments with activity?.run { ViewModelProvider.of (this, ...)}
@elvedinelvis I get ViewModel has no zero argument constructor. Could you share the same fragment?