title: Moving from one Activity to the other on Android
body: <p>I am trying to move from one Activity to another on a simple Android app code. But it doesn't seem to work at all. Once I click the button "Change activity" the app stops working. Here is the code for both activities.</p>
  
  <p>1.The main activity. The one the user sees first when the app is up</p>
  
  <pre><code>package eg.edu.guc;
  
  import android.app.Activity;
  import android.content.Intent;
  import android.os.Bundle;
  import android.view.View;
  import android.widget.Button;
  import android.widget.EditText;
  import android.widget.TextView;
  
  public class HelloAndroidActivity extends Activity {
      Button b1;
      TextView t1;
      EditText e1;
      /** Called when the activity is first created. */
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);
          b1 = (Button) findViewById(R.id.button1);
          b1.setOnClickListener(new View.OnClickListener() {
              public void onClick(View v) {
                  Intent intent = new Intent(HelloAndroidActivity.this,HelloAndroidActivity2.class);
                  HelloAndroidActivity.this.startActivity(intent);
                  //finish();
              }
          });
  
  
  
          t1 = (TextView) findViewById(R.id.TextView1);
          e1= (EditText) findViewById(R.id.editText1);
  
      }
  }
  </code></pre>
  
  <p>2.The second activity that the button "Change Activity" takes the user to:</p>
  
  <pre><code>package eg.edu.guc;
  
  import android.app.Activity;
  import android.os.Bundle;
  import android.widget.ImageView;
  import android.widget.TextView;
  
  public class HelloAndroidActivity2 extends Activity{
      TextView t2;
      ImageView I;
      /** Called when the activity is first created. */
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main2);
          t2 = (TextView) findViewById(R.id.TextView2);
          I = (ImageView) findViewById(R.id.imageView1);
          I.setImageResource(R.drawable.kareem);
      }
  
  }
  </code></pre>
  
  <p>3.Here is main the XML UI for the 1st activity </p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:orientation="vertical" &gt;
      &lt;TextView
          android:id="@+id/TextView1"
          android:layout_marginTop="15dp"
          android:layout_marginBottom="15dp"
          android:layout_width="211dp"
          android:layout_height="wrap_content"
          android:text="Hello Android"
          android:textSize="30dp" /&gt;
  
  
  
      &lt;EditText
          android:id="@+id/editText1"
          android:layout_marginTop="15dp"
          android:layout_marginBottom="15dp"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:inputType="text" /&gt;
  
      &lt;Button
          android:id="@+id/button1"
          android:layout_marginTop="15dp"
          android:layout_marginBottom="15dp"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:text="Change Activity" /&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>4.And finally here is the UI XML file for the second activity </p>
  
  <pre><code> &lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="vertical" &gt;
  
      &lt;TextView
          android:id="@+id/TextView2"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:text="Kareem's Photo" &gt;
  
          &lt;requestFocus /&gt;
      &lt;/TextView&gt;
  
  
  
      &lt;ImageView
          android:id="@+id/imageView1"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:layout_weight="0.21"
          android:src="@drawable/ic_launcher" /&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>