title: Share ViewModel between fragments that are in different Activity
body: <p>I have a ViewModel named SharedViewModel:</p>
  
  <pre><code>public class SharedViewModel&lt;T&gt; extends ViewModel {
  
      private final MutableLiveData&lt;T&gt; selected = new MutableLiveData&lt;&gt;();
  
  
      public void select(T item) {
          selected.setValue(item);
      }
  
      public LiveData&lt;T&gt; getSelected() {
          return selected;
      }
  }
  </code></pre>
  
  <p>I've implemented it based on SharedViewModel example on the Google's Arch ViewModel reference page: </p>
  
  <p><a href="https://developer.android.com/topic/libraries/architecture/viewmodel.html#sharing_data_between_fragments" rel="noreferrer">https://developer.android.com/topic/libraries/architecture/viewmodel.html#sharing_data_between_fragments</a></p>
  
  <blockquote>
    <p>It is very common that two or more fragments in an activity need to communicate with each other. This is never trivial as both
    fragments need to define some interface description and the owner
    activity must bind the two together. Moreover, both fragments must
    handle the case where the other fragment is not yet created or not
    visible.</p>
  </blockquote>
  
  <p>I have two fragments, called <code>ListFragment</code> and <code>DetailFragment</code>. </p>
  
  <p>Until now I used these two fragments inside an activity called <code>MasterActivity</code>, and everything worked well. </p>
  
  <p>I got the ViewModel in <code>ListFragment</code>, selected the value to use it on <code>DetailFragment</code>.</p>
  
  <pre><code>mStepSelectorViewModel = ViewModelProviders.of(getActivity()).get(SharedViewModel.class);
  </code></pre>
  
  <p>However, now, in certain cases, I need that <code>ListFragment</code> (a layout to a different device configuration) will be added to a different activity, called <code>DetailActivity</code>. Is there a way to do that similarly to the above example?  </p>