title: Presenter Instructing Current Activity to Inflate Next Activity; Violation of MVP Rules or Not
body: <p>Considering the fact that in Android, you need a package context to be able to inflate the next activity from the current activity using an intent. However, with the MVP, the presenter is meant to be a pure Java class that is not glued to dependencies like the Android framework itself.</p>
  
  <p>Is it proper to implement two methods in the view; One that asks the presenter to show a new view <strong>showNew(IView activity)</strong> and then the presenter authorizes this request by passing the new view back to the current view and asking it to use its (activity) context to inflate the requested next view.</p>
  
  <p>In other words, the presenter is still the one who orders the creation of the next view, just that it does it through the context of the current view.</p>
  
  <p>See Sample Code below:</p>
  
  <p><strong>View Interface</strong></p>
  
  <pre><code>public interface IBaseView{
      void showAnother(Class nextActivity);
  }
  </code></pre>
  
  <p><strong>Presenter Interface</strong></p>
  
  <pre><code> public interface IBasePresenter {
        void showNew(IBaseView nextActivity);
  }
  </code></pre>
  
  <p><strong>Concrete Presenter</strong></p>
  
  <pre><code>public class Presenter implements IBasePresenter {
  
  IBaseView view;
  
  public Presenter(IBaseView view){
      this.view = view;
  }
  
  @Override
  public void showNew(IBaseView nextActivity) {
      view.showAnother(nextActivity.getClass());
  }
  </code></pre>
  
  <p><strong>Android Activity</strong></p>
  
  <pre><code>public class SampleActivity extends AppCompatActivity implements IBaseView{
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_sample);
  }
  
  public void onClick(View view){
      Presenter presenter = new Presenter(this);
      presenter.showNew(new SampleNextActivity());
  }
  
  @Override
  public void showAnother(Class nextActivity) {
      Intent intent = new Intent(this, nextActivity);
      startActivity(intent);
  }
  
  }
  </code></pre>
  
  <p><strong>Android Next Activity</strong></p>
  
  <pre><code>public class SampleNextActivity extends AppCompatActivity implements IBaseView {
      //activity details here
  }
  </code></pre>
  
  <p><strong>In Summary</strong></p>
  
  <p><em>View creates the next view, but only at the instruction of the presenter</em>. Because the presenter needs the context of the current view to be able to inflate a next view.</p>
  
  <p><strong>Question</strong></p>
  
  <ol>
  <li><p>Is this approach in any way violating the MVP methodology</p></li>
  <li><p>If (1) is a violation or not clean enough, is there a better way to make the presenter create the views (without having knowledge of the Android Context Class) ?</p></li>
  </ol>