title: Moving from one activity to another Activity in Android
body: <p>I want to move from one activity to another (using virtual device). When I click on button to move, My emulator ones a dialog box showing <code>unfortunately SMS1 has stopped working</code> (SMS1 is my app name). </p>
  
  <p>Can anybody help me in correcting my code?</p>
  
  <p><strong>MainActivity.java:</strong></p>
  
  <pre><code>package com.example.sms1;
  
   import android.os.Bundle;
   import android.app.Activity;
   import android.content.Intent;
   import android.view.Menu;
   import android.view.View;
   import android.view.View.OnClickListener;
   import android.widget.Button;
   import android.widget.TextView;
  
   public class MainActivity extends Activity implements OnClickListener
   {
  
  Button b1;
  TextView tv1;
   @Override
   protected void onCreate(Bundle savedInstanceState)
   {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      b1 = (Button) findViewById(R.id.button1);
      tv1 = (TextView) findViewById(R.id.textView1);
  
      b1.setOnClickListener(this);
  
   }
  
  @Override
  public boolean onCreateOptionsMenu(Menu menu)
  {
      // Inflate the menu; this adds items to the action bar if it is present.
      getMenuInflater().inflate(R.menu.main, menu);
      return true;
  }
  
  @Override
  public void onClick(View v)
  {
      // TODO Auto-generated method stub
      Intent i = new Intent(getApplicationContext(),NextActivity.class);
      startActivity(i);
      setContentView(R.layout.avtivity_next);
  }
  
  
  
  }
  </code></pre>
  
  <p><strong>Here is the NextActivity</strong></p>
  
  <pre><code>package com.example.sms1;
  
  import android.os.Bundle;
  import android.app.Activity;
  import android.view.Menu;
  import android.widget.TextView;
  
  public class NextActivity extends Activity {
  
  TextView tv1;
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.avtivity_next);
      tv1 = (TextView) findViewById(R.id.textView1);
  }
  
  
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
      // Inflate the menu; this adds items to the action bar if it is present.
      getMenuInflater().inflate(R.menu.main, menu);
      return true;
  }
  
  }
  </code></pre>
  
  <p><strong>Manifest.XML</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.example.sms1"
  android:versionCode="1"
  android:versionName="1.0" &gt;
  
  &lt;uses-sdk
      android:minSdkVersion="8"
      android:targetSdkVersion="17" /&gt;
  
  &lt;application
      android:allowBackup="true"
      android:icon="@drawable/ic_launcher"
      android:label="@string/app_name"
      android:theme="@style/AppTheme" &gt;
      &lt;activity
          android:name="com.example.sms1.MainActivity"
          android:label="@string/app_name" &gt;
          &lt;intent-filter&gt;
              &lt;action android:name="android.intent.action.MAIN" /&gt;
  
              &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
          &lt;/intent-filter&gt;
      &lt;/activity&gt;
  &lt;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>
  
  <p><strong>NextActivityLayout</strong></p>
  
  <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:paddingBottom="@dimen/activity_vertical_margin"
  android:paddingLeft="@dimen/activity_horizontal_margin"
  android:paddingRight="@dimen/activity_horizontal_margin"
  android:paddingTop="@dimen/activity_vertical_margin"
  tools:context=".NextActivity" &gt;
  
  &lt;TextView
      android:id="@+id/textView1"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="next activity" /&gt;
  
  
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p><strong>MainActivity Layout</strong></p>
  
  <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:paddingBottom="@dimen/activity_vertical_margin"
  android:paddingLeft="@dimen/activity_horizontal_margin"
  android:paddingRight="@dimen/activity_horizontal_margin"
  android:paddingTop="@dimen/activity_vertical_margin"
  tools:context=".MainActivity" &gt;
  
  &lt;TextView
      android:id="@+id/textView1"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="@string/hello_world" /&gt;
  
  &lt;Button
      android:id="@+id/button1"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_below="@+id/textView1"
      android:layout_marginTop="80dp"
      android:layout_toRightOf="@+id/textView1"
      android:text="Button" /&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>