title: How to switch between activities/screens in Android
body: <p>my first Activity Xm</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:background="#a5c63b"
       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;Button
      android:id="@+id/btn1"
      android:layout_width="match_parent"
      android:layout_height="70dp"
      android:layout_alignParentTop="true"
      android:layout_centerHorizontal="true"
      android:layout_marginTop="70dp"
      android:background="#434d23"
      android:text="Ok To Continue"
      android:onClick="frontt"
      android:textColor="#a5c63b" /&gt;
  &lt;ImageView
      android:id="@+id/imageView11"
      android:layout_width="250dp"
      android:layout_height="250dp"
      android:layout_alignParentBottom="true"
      android:layout_centerHorizontal="true"
      android:src="@drawable/question" /&gt;
  &lt;TextView
      android:id="@+id/txtview11"
      android:layout_width="match_parent"
      android:layout_height="20dp"
      android:layout_alignParentLeft="true"
      android:layout_alignParentTop="true"
      android:text="Loading..."
      android:textSize="12dp" /&gt;
    &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>This is my Second Activity Xml</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:background="#a5c63b"
       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;Button
      android:id="@+id/btn"
      android:layout_width="match_parent"
      android:layout_height="70dp"
       android:onClick="onClick"
      android:layout_alignParentTop="true"
      android:layout_centerHorizontal="true"
      android:layout_marginTop="70dp"
      android:background="#434d23"
      android:text="OK"
      android:textColor="#a5c63b" /&gt;
  
  &lt;EditText
      android:id="@+id/txtedit"
      android:layout_width="match_parent"
      android:layout_height="20dp"
      android:layout_alignLeft="@+id/button1"
      android:layout_alignParentTop="true"
      android:layout_marginTop="50dp"
      android:background="#edf2db"
      android:ems="10"
      android:inputType="numberDecimal" /&gt;
  
  &lt;ImageView
      android:id="@+id/imageView1"
      android:layout_width="250dp"
      android:layout_height="250dp"
      android:layout_alignParentBottom="true"
      android:layout_centerHorizontal="true"
      android:src="@drawable/question" /&gt;
  
  &lt;TextView
      android:id="@+id/txtview"
      android:layout_width="match_parent"
      android:layout_height="20dp"
      android:layout_alignBottom="@+id/txtedit"
      android:layout_alignLeft="@+id/txtedit"
      android:layout_marginBottom="21dp"
      android:text="Guess Single Digit Number"
      android:textSize="12dp" /&gt;
  
  &lt;TextView
      android:id="@+id/txtview2"
     android:layout_width="match_parent"
      android:layout_height="20dp"
      android:layout_alignLeft="@+id/btn"
      android:layout_below="@+id/btn"
      android:text="TextView" /&gt;
  
   &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>this is my first java file code</p>
  
  <pre><code>   package com.example.game;
     import android.media.MediaPlayer;
     import android.os.Bundle;
     import android.view.View;
     import android.view.View.OnClickListener;
      import android.app.Activity;
     import android.content.Intent;
       import android.view.Menu;
      import android.widget.Button;
  
  
  public class MainActivity extends Activity {
    MediaPlayer btnsound;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.front);
      Button next = (Button) findViewById(R.id.btn1);
  
  
      btnsound = MediaPlayer.create(MainActivity.this,R.raw.game);
      btnsound.start();
  
  
  
  
      next.setOnClickListener(new OnClickListener()
  {
      public void onClick(View v)
      {
  
          Intent nextScreen = new Intent(getApplicationContext(), CopyOfMainActivity.class);
  
          startActivity(nextScreen);
          //finish();
      }
   } );
  
  }
  
  @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>this is my Second java file</p>
  
  <pre><code>   package com.example.game;
     import java.util.Random;
      import android.media.MediaPlayer;
      import android.os.Bundle;
     import android.view.View;
     import android.view.View.OnClickListener;
     import android.widget.Button;
     import android.widget.EditText;
     import android.widget.ImageView;
     import android.widget.TextView;
    import android.app.Activity;
    import android.view.Menu;
  
   public class CopyOfMainActivity extends Activity {
  MediaPlayer btnsound;
  Random random = new Random();
  int randnumber = random.nextInt(10);
  Button b2;
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      btnsound = MediaPlayer.create(CopyOfMainActivity.this,R.raw.game);
      btnsound.start();
      b2= (Button) findViewById(R.id.btn);
      b2.setOnClickListener(new OnClickListener()
  {
      public void onClick(View v)
      {
  
           EditText input = (EditText)findViewById(R.id.txtedit);
           TextView resultText = (TextView) findViewById(R.id.txtview2);
           String inputstring = input.getText().toString();
              int number = Integer.parseInt(inputstring);    
            if(randnumber==number)
            {
                resultText.setText("you win" );
                ImageView image = (ImageView) findViewById(R.id.imageView1);
                  image.setImageResource(R.drawable.win);
            }
            else if (number&gt;randnumber)
            {
  
                resultText.setText("you guess high number" );
                ImageView image = (ImageView) findViewById(R.id.imageView1);
                  image.setImageResource(R.drawable.tryagain);
            }
            else if (number&lt;randnumber)
            {
  
                resultText.setText("you guess low number" );
                ImageView image = (ImageView) findViewById(R.id.imageView1);
                  image.setImageResource(R.drawable.lose);
            }
      }
   } );
  
  }
  
  @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>I have one button on First Activity xml layout .The first Activity Layout display after run application but whenever i click on button on first xml first want to go on next laytout after clicking then this error show in LogCat tab and application stop working. </p>
  
  <blockquote>
    <p>AndroidRuntime at dalvik.system.NativeStart.main(Native Method)</p>
  </blockquote>
  
  <p>what i should do?   </p>