How to return a string from an activity launched for a result

I started work for the result, but how to return a string as a parameter from this activity?

+5
source share
3 answers

just use the following code:

Intent intent=new Intent();
intent.putExtra("RESULT_STRING", string);
setResult(RESULT_OK, intent);
finish();

get the value from this intent in the onActivtyResult method when invoking activity:

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
   if (requestCode == CREATE_REQUEST_CODE) {
      if (resultCode == RESULT_OK) {
        //Use Data to get string
        String string = data.getStringExtra("RESULT_STRING");
      }
   }
}
+14
source

putExtra intent setResult(),

Intent data = new Intent();
data.putExtra("myobj", value);
setResult(Activity.RESULT_OK, data);
+1

All Articles