0

i want to start activityB from activityA and return string from activityB then resume activityA is it possible? i refer Android: Capturing the return of an activity

Community
  • 1
  • 1
madwhoo
  • 99
  • 1
  • 1
  • 10

2 Answers2

1

You will have to Work on onActivityResult(). Here are some Tutorials.

One, Two

In example One you will find your Answer. Hope this is Enough.

Bhavin
  • 6,020
  • 4
  • 24
  • 26
0

You can use startActivityForResult() method if you need to pass data back from an activity. E.x: return data from Activity B

Activity A:

Step1:Call StartActivityForResult() method

Intent i = new Intent(A.this,B.class);
// use startActivityForResult(Intent,request_code)  method()
//with request_code is used to identify.
starActivityForResult(i,1)

Step2: You must implements onActivityResult(int requestCode,int resultCode,Intent data) method

//check requestCode and resultCode    
if(requestCode==1)
{

  if(resultCode==RESULT_OK)

  {
    //get Data
    String temp =  data.getData().toString();
   }  


}

Activity B:

 //set Data return Activity B at anywhere you want
 Intent data = new Intent()
 data.setData("String_Test");

 setResult(RESULT_OK,data)
 //close the activity
 finish();

Note: instead of using setData method(), you also able to use putExtras(Bunble object) to send data.

secretlm
  • 2,361
  • 2
  • 27
  • 38