8

I have started Activity for result, but how to return string like parameter from that activity ?

Damir
  • 54,277
  • 94
  • 246
  • 365

3 Answers3

18

just use following code block:

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

get value from this intent in onActivtyResult method in calling 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");
      }
   }
}
jeet
  • 29,001
  • 6
  • 52
  • 53
2

You just need to putExtra in the intent and the call setResult(),

Intent data = new Intent();
data.putExtra("myobj", value);
setResult(Activity.RESULT_OK, data);
Lalit Poptani
  • 67,150
  • 23
  • 161
  • 242
1

The documentation says it all. You set the result by calling setResult and you read it in the onActivityResult method.

kgiannakakis
  • 103,016
  • 27
  • 158
  • 194