title: Android startActivityForResult()
body: <p>I just started learning android programming but I have a problem starting Activity for Result(using onActivityResult(), setResult()).</p>
  
  <p>First, there is three activity - Main, Register, SubActivity(But my question is regard to two activity - Main, Register). I registered all of them to 'AndroidManifest.xml' like this:</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.wakwakwak.iwak.myapp" &gt;
      &lt;uses-permission android:name="android.permission.VIBRATE"/&gt;
      &lt;application
          android:allowBackup="true"
          android:icon="@mipmap/ic_launcher"
          android:label="@string/app_name"
          android:theme="@style/AppTheme" &gt;
          &lt;activity
              android:name=".Main"
              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;activity android:name=".SubActivity"
              android:label="Here is SubWorld!"&gt;
  
          &lt;/activity&gt;
          &lt;activity android:name=".Register"
              android:label="Register"&gt;
  
          &lt;/activity&gt;
      &lt;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>
  
  <p>As you see, three activities are successfully registered.</p>
  
  <p>This is Main Activity. </p>
  
  <p><img src="https://i.stack.imgur.com/lCzUE.png" alt="Main Activity"></p>
  
  <p>and If I touch 'REG' Button, We move to 'Register' Activity.</p>
  
  <p><img src="https://i.stack.imgur.com/djnDc.png" alt="Register Activity"></p>
  
  <p>If REG is touched, Register Activity returns information to Main Activity and Main Activity saves it to ArrayList.</p>
  
  <p>Code below is Main Activity(Main.java).</p>
  
  <pre><code>package com.wakwakwak.iwak.myapp;
  
  import android.app.Activity;
  import android.content.Context;
  import android.content.Intent;
  import android.os.Bundle;
  import android.os.Vibrator;
  import android.view.View;
  import android.widget.EditText;
  import android.widget.Toast;
  
  import java.util.ArrayList;
  
  
  public class Main extends Activity {
      private static ArrayList&lt;Person&gt; users;
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          Vibrator vibrator = (Vibrator)getSystemService(Context.VIBRATOR_SERVICE);
          vibrator.vibrate(300);
      }
  
      public void onClick(View v){
          EditText edId = (EditText)findViewById(R.id.edit_id);
          EditText edPw = (EditText)findViewById(R.id.edit_pw);
          Vibrator vibrator = (Vibrator)getSystemService(Context.VIBRATOR_SERVICE);
          switch(v.getId()){
              case R.id.btn_login:
                  vibrator.vibrate(300);
                  Person person = new Person(edId.getText().toString(),edPw.getText().toString());
  
                  Intent intent1 = new Intent(this, SubActivity.class);
                  intent1.putExtra("person",person);
                  startActivity(intent1);
                  break;
              case R.id.btn_register:
                  vibrator.vibrate(300);
                  Intent intent2 = new Intent(this,Register.class);
                  startActivityForResult(intent2, 0);
                  break;
          }    
      }
  
      @Override
      protected void onActivityResult(int requestCode, int resultCode, Intent data) {
          switch(requestCode)
          {
              case 0:
                  Person person = (Person)data.getSerializableExtra("person");
                  users.add(person);
                   Toast.makeText(this,person.toString(),Toast.LENGTH_SHORT).show();
                  break;
          }
      }
  }
  </code></pre>
  
  <p>And Code below are Register Activity(Register.java)</p>
  
  <pre><code>package com.wakwakwak.iwak.myapp;
  
  import android.app.Activity;
  import android.content.Intent;
  import android.os.Bundle;
  import android.view.View;
  import android.widget.EditText;
  import android.widget.Toast;
  
  public class Register extends Activity {
      @Override
      protected void onCreate(Bundle savedInstanceState){
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_register);
      }
  
      public void onClick(View view) {
          EditText editId = (EditText)findViewById(R.id.edit_id);
          EditText editPw = (EditText)findViewById(R.id.edit_pw);
          EditText editPwAgain = (EditText)findViewById(R.id.edit_pwagain);
          switch(view.getId()){
              case R.id.btn_register:
                  if(!editPw.getText().toString().equals(editPwAgain.getText().toString())){
                      editPw.setText("");
                      editPwAgain.setText("");
                      Toast.makeText(this,"Passwords are not equal each other",Toast.LENGTH_SHORT).show();
                  }
                  else{
                      Person person = new Person(editId.getText().toString(),editPw.getText().toString());
                      Intent intent2 = new Intent();
                      intent2.putExtra("person",person);
                      setResult(0,intent2);
                      finish();
                  }
                  break;
          }
      }
  }
  </code></pre>
  
  <p>(Person is a class which have a member 'id' and 'pw'. It seems there's no problem on Person class)</p>
  
  <p>It seems Register activity itself works well - It shows error toast when each password are different, but when both of them are same(when passing to Main activity), Error occurs: 'Myapp is stopped' I really can't know what is problem!! Please Let me know what is wrong :(</p>