title: Android MVVM: Activity with multiple Fragments - Where to put shared LiveData?
body: <p>I have an architectural question about the android ViewModels:</p>
  
  <p>Let's say that in my App I have an Activity with two Fragments inside (using a Viewpager). The two fragments do different things (therefore may have their own ViewModel?), but they also both need various data that is similar. </p>
  
  <p>This is for example the state if a network connection is available or not (and both fragments show different error UIs if there is no connection), or some user setting that comes via a Push from a server and affects both fragments equally.</p>
  
  <p>This looks something like this:</p>
  
  <p><a href="https://i.stack.imgur.com/fnss1.png" rel="noreferrer"><img src="https://i.stack.imgur.com/fnss1.png" alt="enter image description here"></a></p>
  
  <p>Now my question is how to deal with that situation when using ViewModels? 
  Is it good that a view observes multiple ViewModels, like it would be if I have a ViewModel for the Activity (holding the state that both need equally) and one for each fragment, like this:</p>
  
  <p><a href="https://i.stack.imgur.com/7CufL.png" rel="noreferrer"><img src="https://i.stack.imgur.com/7CufL.png" alt="enter image description here"></a></p>
  
  <p>This was hinted <a href="https://github.com/googlesamples/android-architecture-components/issues/205" rel="noreferrer">here</a> for example, but it is not a good practice, as the <a href="https://stackoverflow.com/questions/9413034/viewmodel-per-view-or-per-model">relationship in MVVM</a> generally is </p>
  
  <blockquote>
    <p>View n - 1 ViewModel n - 1 Model</p>
  </blockquote>
  
  <p>But I am not sure where the right place for such shared LiveData is in my case?</p>