I have an architectural question about ViewModels androids:
Let's say that in my application I have activity with two fragments inside (using Viewpager). These two snippets do different things (why can they have their own ViewModel?), But they also need different data, similar.
This is, for example, a state if a network connection is available or not (and both fragments show different error interfaces if there is no connection), or some user settings that come through Push from the server and affect both fragments equally.
It looks something like this:

Now my question is how to deal with this situation when using ViewModels? Is it good that several ViewModels are observed in the view, as if I had a ViewModel for Activity (supporting a state that is the same) and one for each fragment, for example:

This has been outlined here , but this is not a good practice, since relationships in MVVM are usually
View n - 1 ViewModel n - 1 Model
But I'm not sure where is the right place for such a common LiveData in my case?
android mvvm
stamanuel
source share