title: Android call View Controller method from ViewModel
body: <p>I started playing around with Android JetPack (ViewModel, Architecture Components, LIfeCycle and so on).
  Untill now, I was working with Model View Presenter architecture, and actually I found it a quite easy to test and maintain architecture.</p>
  
  <p>On the other hand, The big advantage I can see by using ViewModels instead, is their native coupling with Activities and Fragments lifecycle, which always was one of the biggest pains for Android developer, so I think this is a very big step forward.</p>
  
  <p>Said that, I think there is a big disavantage though: with this new approach, it seems much more tricky to call Activity's or Fragment's methods, because, as stated in the official docs</p>
  
  <blockquote>
    <p>A ViewModel must never reference a view, Lifecycle, or any class that
    may hold a reference to the activity context.</p>
  </blockquote>
  
  <p>In MVP approach, the Presenter had a contract with the view and could call all of its methods. I made some research on how to address this scenario with Architecture components, but it seem there is no easy and painless way to do that: at the end you always have to handle states in ViewModel and react to these  changes in Activities and Fragments. Someone suggest to use <a href="https://github.com/googlesamples/android-architecture/blob/dev-todo-mvvm-live/todoapp/app/src/main/java/com/example/android/architecture/blueprints/todoapp/SingleLiveEvent.java" rel="nofollow noreferrer">SingleLiveEvent</a> class, which makes it a little bit easier, but still much more painfull than before.</p>
  
  <p>So my question is: </p>
  
  <p>The docs say you cannot reference anything holding a reference to an Activity Context (to avoid memory leaks I guess), but what if I do that and then I clear all references in ViewModel's onCleared()?</p>