I'm working on a project that uses multiple Fragments and single Activity. Some of the Fragments that have similar behavior has a Shared ViewModel scoped to individual Nested NavGraphs
. But at the start of the activity, all Fragments needs to check one common property(internet connection livedata)
present in Activity ViewModel. Now since the start of the app, all fragments require to check Internet Connection LiveData
which is present within the ActivityViewModel
, how should I pass the LiveData or the ActivityViewModel instance to individual Fragments? I tried using a Single ViewModel scoped to Activity for all fragments
but doing that way will make the ViewModel complex. How should I solve the problem?. Should I get the instance of ActivityViewModel
inside each Fragment? But doing these will result my fragment to have two Viewmodels- one from Activty another from Navgraph
. What should I do? What is the recommended approach?
Any help would be appreciated.
Thanks in advance