title: passing second data after clicking the button in android
body: <p>i actually take this code form <a href="http://www.vogella.com/articles/AndroidIntent/article.html" rel="nofollow">vogella.com</a>.</p>
  
  <p>i want to pass the data from the second activity to first activity when click the button in second activity. to make sure the value passing is correct, i want it display as a toast when going back to first activity.</p>
  
  <p>this is my code on the firstactivity_layout. res/activity_intentintent.xml</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/TextView01"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:minHeight="60dip"
          android:text="First Activity. Press button to call second activity"
          android:textSize="20sp" &gt;
      &lt;/TextView&gt;
  
      &lt;Button
          android:id="@+id/Button01"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:onClick="onClick"
          android:text="Calling an intent" &gt;
      &lt;/Button&gt;
  
  &lt;/LinearLayout&gt; 
  </code></pre>
  
  <p>this is the second code for layout. res/picklayout.xml</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;EditText
          android:id="@+id/input11"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:ems="10" &gt;
  
          &lt;requestFocus /&gt;
      &lt;/EditText&gt;
  
  
  
      &lt;EditText
          android:id="@+id/input22"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:ems="10" /&gt;
  
  
      &lt;Button
          android:id="@+id/button1"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:text="Button" /&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>this is the activity code for the first layout, IntentintentActivity.java</p>
  
  <pre><code>public class IntentintentActivity extends Activity {
      Button btn1;
      private static final int REQUEST_CODE = 10;
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_intentintent);
  
      }
  
      public void onClick(View view) {
          Intent i = new Intent(this, PickActivity.class);
          i.putExtra("Value1", "This value one for ActivityTwo ");
          i.putExtra("Value2", "This value two ActivityTwo");
          // Set the request code to any code you like, you can identify the
          // callback via this code
          startActivityForResult(i, REQUEST_CODE);
        }
  
        @Override
        protected void onActivityResult(int requestCode, int resultCode, Intent data) {
          if (resultCode == RESULT_OK &amp;&amp; requestCode == REQUEST_CODE) {
            if (data.hasExtra("returnKey1")) {
              Toast.makeText(this, data.getExtras().getString("returnKey1"),
                  Toast.LENGTH_SHORT).show();
            }
          }
        }
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          // Inflate the menu; this adds items to the action bar if it is present.
          getMenuInflater().inflate(R.menu.activity_intentintent, menu);
          return true;
      }
  </code></pre>
  
  <p>and the last is the second activity, PickActivity.java</p>
  
  <pre><code>public class PickActivity extends Activity{ 
  Button submit;
  EditText text1, text2;
  
  public void onCreate(Bundle savedInstanceState){
      super.onCreate(savedInstanceState);
          setContentView(R.layout.picklayout);
  
          Bundle extras = getIntent().getExtras();
          if (extras == null) {
            return;
          }
          String value1 = extras.getString("Value1");
          String value2 = extras.getString("Value2");
          if (value1 != null &amp;&amp; value2 != null) {
            text1 = (EditText) findViewById(R.id.input11);
            text2 = (EditText) findViewById(R.id.input22);
            text1.setText(value1);
            text2.setText(value2);            
  
          }   
          submit = (Button)findViewById(R.id.button1);
          /*
          submit.setOnClickListener(new OnClickListener(){
              public void onClick(View v){
                  Toast.makeText(this, text1.getText(), 2500).show();
              }
          });
          */
      }
  
  public void onClick(View v) {
      Toast.makeText(this, text1.getText(), 2500).show();
      finish();
    }     
  
        @Override
        public void finish() {
          Intent data = new Intent(this, IntentintentActivity.class);
          Toast.makeText(this, "finish state", 2500).show();
          // Return some hard-coded values
          data.putExtra("returnKey1", "Swinging on a star. ");
          data.putExtra("returnKey2", "You could be better then you are. ");
          setResult(RESULT_OK, data);
          int result = 1;
          //startActivityForResult(data, result);
          super.finish();
        }
  </code></pre>
  
  <p>}</p>
  
  <p>i tried to put listener for the button in the second activity like this.</p>
  
  <pre><code>public class PickActivity extends Activity{ 
  Button submit;
  EditText text1, text2;
  
  public void onCreate(Bundle savedInstanceState){
      super.onCreate(savedInstanceState);
          setContentView(R.layout.picklayout);
  
          Bundle extras = getIntent().getExtras();
          if (extras == null) {
            return;
          }
          String value1 = extras.getString("Value1");
          String value2 = extras.getString("Value2");
          if (value1 != null &amp;&amp; value2 != null) {
            text1 = (EditText) findViewById(R.id.input11);
            text2 = (EditText) findViewById(R.id.input22);
            text1.setText(value1);
            text2.setText(value2);            
  
          }   
          submit = (Button)findViewById(R.id.button1);
  
          submit.setOnClickListener(new OnClickListener(){
              public void onClick(View v){
                  Toast.makeText(this, text1.getText(), 2500).show();
              }
          });
  
      }
  </code></pre>
  
  <p>however it said <code>Toast.makeText(...)</code> is not applicable for the argument(new View.onClickListener). </p>
  
  <p>does anyone know how to solve this please. thank you.</p>