send data to previous activity android code example

Example: send data to previous activity android

// first 
Intent i = new Intent(this, Activity2.class);
startActivityForResult(i, 1);

// second
Intent intent = new Intent();
intent.putExtra("editTextValue", "value_here")
setResult(RESULT_OK, intent);        
finish();

// third
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == 1) {
         if(resultCode == RESULT_OK) {
             String strEditText = data.getStringExtra("editTextValue");
         }     
    }
}

Tags:

Misc Example