8

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

Damir
  • 51,611
  • 92
  • 240
  • 358

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
  • 28,501
  • 6
  • 50
  • 52
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
  • 66,608
  • 21
  • 157
  • 241
1

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

kgiannakakis
  • 100,996
  • 27
  • 157
  • 193