title: What should be done in Activity/Fragment and ViewModel in MVVM
body: <p>Our company has been developing Android application using MVP pattern a while. With MVP, we put all business logic inside the presenter and the Activity/Fragment then just responsible for view update when receiving event callback from presenter.</p>
  
  <p>Now, we decided to try MVVM using Android Databinding. It seems that with MVVM, we can put all the business logic in the ViewModel (just like Presenter in MVP) and also notify the view(s) of any changes to data model, all in one object.</p>
  
  <p>But then, this raise question in our mind, what should we left to be handle by the Activity/Fragment? Since we adopted the MVP pattern to avoid <strong>fat-activity/fragment</strong>. We don't want to have <strong>slim-activity/fragment</strong> and then <strong>fat-viewmodel</strong>.</p>
  
  <p>What we think we can left to be handle by Activity/Fragment so far</p>
  
  <ul>
  <li>Request/Check permission</li>
  <li>Access Context</li>
  <li>Access Resources</li>
  </ul>
  
  <p>Every correction, comment or suggestion are welcome since I'm fairly new to MVVM, even if it seems to be similar to MVP.</p>
  
  <p>Thank you.</p>
  
  <p><strong>A bit more question</strong></p>
  
  <p>Is it possible and good practice to combine MVVM with listener (like MVP)? For example</p>
  
  <pre><code>public class MainActivityViewModel extends BaseObservable {
  
      MainActivityViewModelListener listener;
      User user;
  
      public void setMainActivityViewModelListener(MainActivityViewModelListener listener) {
          this.listener = listener;
      }
  
      public void refreshUser(View v) {
          // some user update via Internet
          notifyPropertyChanged(BR.userAlias);
  
          if (listener != null) {
              listener.onUserRefreshed(user);
          }
      }
  
      @Bindable
      public void getUserAlias() {
          return user.getAlias();
      }
  }
  
  public interface MainActivityViewModelListener {
      void onUserRefreshed(User user);
  }
  
  public class MainActivity implements MainActivityViewModelListener {
  
      MainActivityBinding binding;
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          binding = DataBindingUtil.setContentView(R.layout.main_activity);
  
  
          MainActivityViewModel viewModel = new MainActivityViewModel();
          viewModel.setMainActivityViewModelListener(this);
          binding.setMainActivityViewModel(viewModel);
      }
  
      @Override
      public void onUserRefreshed(User user) {
          // do some update
      }
  }
  </code></pre>