title: Switching the layouts through Intents
body: <p>I have two layouts(xml files) and I want to flip from one page to another, the two xml files are main.xml and register.xml, if I click signin button in main.xml the page should turn and show register.xml  and also in register.xml if I click the submit button it  should turn to main.xml I tried a lot with the activity and i coldnt do it as I am new to android</p>
  
  <p>please someone  share the code for me,</p>
  
  <p>here is my two xml codes</p>
  
  <p>main.xml</p>
  
  <p>
  </p>
  
  <pre><code>&lt;LinearLayout
  android:orientation="horizontal" 
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:layout_marginTop="10dp" android:background="@drawable/loginapp"&gt;
  </code></pre>
  
  <p>
      </p>
  
  <pre><code>&lt;RelativeLayout android:id="@+id/relativeLayout1" android:gravity="center" android:layout_marginTop="25dip" android:layout_height="177dip" android:background="@drawable/login_form_bg_green" android:layout_width="296dip"&gt;
   &lt;EditText android:layout_marginRight="0dip"  android:id="@+id/userNameBox" android:layout_width="200px" android:background="@android:drawable/editbox_background" android:maxLines="1" android:layout_marginLeft="85dip" android:inputType="text" android:layout_height="wrap_content"&gt;&lt;/EditText&gt;
   &lt;EditText android:layout_marginRight="0dip"  android:id="@+id/passwordBox" android:layout_width="200px" android:background="@android:drawable/editbox_background" android:maxLines="1" android:layout_marginTop="45dip" android:layout_marginLeft="85dip" android:inputType="text|textVisiblePassword" android:layout_height="wrap_content"&gt;&lt;/EditText&gt;
  &lt;/RelativeLayout&gt;
  
  &lt;LinearLayout android:id="@+id/ll_three" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:layout_below="@+id/ll_two" android:gravity="center"&gt;
    &lt;Button 
      android:text="Sign In"
      android:id="@+id/Button01"
      android:layout_width="wrap_content" 
      android:layout_marginTop="5dip"
      android:layout_marginRight="15dip"
      android:layout_height="wrap_content"/&gt;
  &lt;Button 
      android:layout_height="wrap_content" 
      android:layout_width="wrap_content" 
      android:layout_marginTop="5dip"
      android:id="@+id/Button02"
      android:text="New user"/&gt;
  </code></pre>
  
  <p></p>
  
  <p></p>
  
  <p>register.xml is</p>
  
  <p>
  </p>
  
  <pre><code>&lt;TableRow&gt;
   &lt;TextView android:id="@+id/TextView"   
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:text=" REGISTER:"/&gt;    
  &lt;/TableRow&gt;
  
  &lt;TableRow&gt;
      &lt;TextView android:id="@+id/TextView01"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:text="First Name:"/&gt;
  &lt;EditText android:layout_marginRight="0dip"
    android:id="@+id/userNameBox" android:background="@android:drawable/editbox_background"
      android:maxLines="1" android:layout_marginLeft="15dip"   android:layout_weight="1"
      android:inputType="text" android:layout_height="35px" android:layout_width="0dip"&gt;&lt;/EditText&gt;
  
  
  &lt;/TableRow&gt;
  
  &lt;TableRow&gt;
  &lt;TextView android:id="@+id/TextView02"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:text="Last Name:"/&gt;
  &lt;EditText android:layout_marginRight="0dip"
    android:id="@+id/userNameBox" android:layout_width="200px"  android:layout_weight="1" 
    android:background="@android:drawable/editbox_background" android:maxLines="1"
     android:layout_marginLeft="15dip" android:inputType="text" 
     android:layout_height="35px"&gt;&lt;/EditText&gt;
  &lt;/TableRow&gt;
  
  
  &lt;TableRow&gt;
      &lt;TextView android:id="@+id/TextView03"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:text="Email:"/&gt;
  &lt;EditText 
   android:id="@+id/userNameBox" android:layout_width="200px"
    android:background="@android:drawable/editbox_background"  android:layout_weight="1"
     android:maxLines="1" android:layout_marginLeft="15dip" android:layout_marginRight="0dip"  
     android:inputType="text" android:layout_height="35px"&gt;
     &lt;/EditText&gt;
  &lt;/TableRow&gt;
  
  &lt;TableRow&gt;
   &lt;TextView android:id="@+id/TextView03"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:text="Mobile No:"/&gt;
  &lt;EditText android:layout_marginRight="0dip" 
   android:id="@+id/userNameBox" android:layout_width="200px"   android:layout_weight="1"
    android:background="@android:drawable/editbox_background"
     android:maxLines="1" android:layout_marginLeft="15dip"
      android:inputType="text" android:layout_height="35px"&gt;
      &lt;/EditText&gt;
  
  &lt;/TableRow&gt;   
  </code></pre>
  
  <p>
    
    
  </p>
  
  <p>HERE ARE MY JAVA FILES</p>
  
  <p>login.java</p>
  
  <pre><code>package com.android;
  
  
  import android.app.Activity;
  import android.content.Intent;
  import android.os.Bundle;
  import android.view.View;
  import android.widget.Button;
  
  public class Login extends Activity {
      /** Called when the activity is first created. */
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);
  
          Button newuser = (Button) findViewById(R.id.Button02);
          newuser.setOnClickListener(new View.OnClickListener() {
              public void onClick(View view) {
                  Intent myIntent = new Intent(view.getContext(), Register.class);
                  startActivityForResult(myIntent, 0);
              }
  
          });
      }
  }
  
  
  
  
  Register.java
  
  
  package com.android;
  
  import android.app.Activity;
  import android.content.Intent;
  import android.os.Bundle;
  import android.view.View;
  import android.widget.Button;
  
  public class Register extends Activity {
  
      /** Called when the activity is first created. */
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.register);
  
          Button register = (Button) findViewById(R.id.Button03);
          register.setOnClickListener(new View.OnClickListener() {
              public void onClick(View view) {
                  Intent intent = new Intent();
                  setResult(RESULT_OK, intent);
                  finish();
              }
  
          });
      }}
  </code></pre>
  
  <p>while debugging the project  these are the DDMS errors I found</p>
  
  <p>Android [Android Application]<br>
      DalvikVM[localhost:8759]<br>
          Thread [&lt;1> main] (Suspended (exception RuntimeException))<br>
              ActivityThread.performLaunchActivity(ActivityThread$ActivityRecord, Intent) line: 2585<br>
              ActivityThread.handleLaunchActivity(ActivityThread$ActivityRecord, Intent) line: 2679<br>
              ActivityThread.access$2300(ActivityThread, ActivityThread$ActivityRecord, Intent) line: 125 
              ActivityThread$H.handleMessage(Message) line: 2033<br>
              ActivityThread$H(Handler).dispatchMessage(Message) line: 99 
              Looper.loop() line: 123 
              ActivityThread.main(String[]) line: 4627<br>
              Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method]<br>
              Method.invoke(Object, Object...) line: 521<br>
              ZygoteInit$MethodAndArgsCaller.run() line: 868<br>
              ZygoteInit.main(String[]) line: 626 
              NativeStart.main(String[]) line: not available [native method]<br>
          Thread [&lt;6> Binder Thread #2] (Running) 
          Thread [&lt;5> Binder Thread #1] (Running</p>
  
  <p>LOGCAT showing this</p>
  
  <p>04-24 16:24:18.965: ERROR/HierarchicalStateMachine(58): TetherMaster - unhandledMessage: msg.what=3
  04-24 16:24:20.415: WARN/ActivityManager(58): Activity idle timeout for HistoryRecord{44f2b188 com.android.launcher/com.android.launcher2.Launcher}
  04-24 16:24:22.965: WARN/WindowManager(58): App freeze timeout expired.
  04-24 16:24:22.965: WARN/WindowManager(58): Force clearing freeze: AppWindowToken{450698d0 token=HistoryRecord{44f2b188 com.android.launcher/com.android.launcher2.Launcher}}
  04-24 16:24:23.645: WARN/GoogleLoginService(180): Device has no accounts: sending Intent { act=com.google.android.gsf.LOGIN_ACCOUNTS_MISSING }
  04-24 16:24:31.296: WARN/PackageManager(58): Code path for pkg : com.android.cardioworld changing from /data/app/com.android.cardioworld-1.apk to /data/app/com.android.cardioworld-2.apk
  04-24 16:24:31.296: WARN/PackageManager(58): Resource path for pkg : com.android.cardioworld changing from /data/app/com.android.cardioworld-1.apk to /data/app/com.android.cardioworld-2.apk
  04-24 16:24:34.216: WARN/RecognitionManagerService(58): no available voice recognition services found
  04-24 16:24:36.214: WARN/SystemClock(123): Unable to set rtc to 1303642476: Invalid argument
  04-24 16:24:41.174: WARN/ActivityThread(318): Application com.android.cardioworld is waiting for the debugger on port 8100...
  04-24 16:24:50.686: WARN/ActivityManager(58): Launch timeout has expired, giving up wake lock!
  04-24 16:24:51.170: WARN/ActivityManager(58): Activity idle timeout for HistoryRecord{450caa98 com.android.cardioworld/.login}</p>