title: How to scope a view model to a parent fragment?
body: <p>So I'm using the new navigation component (with the one activity principle) and communicating between each fragment using shared view models, however, I've come to a point where I sometimes need to clear the view model but I can't find a good place to clear it. But tbh I think rather than trying to clear it myself, I should really be allowing the framework to do it for me, but it doesn't because the view models are shared and scoped to the activity, but I think I can scope them to a parent fragment, I made a drawing to illustrate what I'm trying to do.<a href="https://i.stack.imgur.com/21v2k.png" rel="noreferrer"><img src="https://i.stack.imgur.com/21v2k.png" alt="my navigation flow"></a> so I only want to clear the 2 view models when I navigate back from "Child 1 Child a" currently the view models are never cleared, trying to get the view model currently by calling 'this' in the fragment and getParentFragment in the child doesn't work, can anyone provide an example?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>It looks like I was already doing something similar but it's not working in my case so I will add some code, here is how I access the first view model in the parent fragment</p>
  
  <pre><code>model = ViewModelProviders.of(this).get(RequestViewModel.class);
  </code></pre>
  
  <p>and then in the child fragment, I'm doing this </p>
  
  <pre><code>requestViewModel = ViewModelProviders.of(getParentFragment()).get(RequestViewModel.class);
  </code></pre>
  
  <p>but it's not keeping the data between them, they both have observers attached</p>