title: How to start an activity from a plain non-activity java class?
body: <p>I want to implement MVVM pattern using data-binding in my app. Here's the login button from my layout file:</p>
  
  <pre><code>&lt;Button
       android:id="@+id/login"
       android:layout_width="0dp"
       android:layout_height="50dp"
       android:text="@{mainViewModel.name}"
       android:textColor="@color/white"
       android:onClick="@{mainViewModel.startNewActivity}"/&gt;
  </code></pre>
  
  <p>The logic is, on clicking this login button, a new activity should be started. I'm a beginner in android, and my question is should I keep the startActivity part in my MainActivity or in my ViewModel class? (If I want it to be in accordance with the MVVM pattern)</p>
  
  <p>If it should be in the mainActivity, I would replace the last line with 
  <code>android:onClick="startNewActivity"</code> and then define the method in my MainActivity.</p>
  
  <p>But, if it is to be placed in the ViewModel class, declaring the following method:</p>
  
  <pre><code>public void startNewActivity(View view) {
      Intent login = new Intent(MainActivity.class, LoginActivity.class);
      startActivity(login);
  }
  </code></pre>
  
  <p>is giving error:</p>
  
  <pre><code>Cannot resolve constructor 'Intent(java.lang.Class&lt;package.name.MainActivity&gt;,java.lang.Class&lt;package.name.LoginActivity&gt;)'
  </code></pre>
  
  <p>How do I start the LoginActivity from my ViewModel class then?</p>