How send result to back to previous activity in an

2019-09-21 05:23发布

i use three activity ActiviytA, ActivityB and ActivityC.from ActivityA have onActivtResult function i need result from Activityc in b/w i travel through the activityB

2条回答
神经病院院长
2楼-- · 2019-09-21 06:10

Thats very easy. You also can implement an onActivityResult inside ActivityB and then just pass it back to activity A:

if(RESULT_OK)
{
//GET data passedback
Intent returnIntent = new Intent();
returnIntent.putExtra(your extra data);
setResult(RESULT_OK, returnIntent);
finish()
}

this is the way I always use my home button implementations.

查看更多
你好瞎i
3楼-- · 2019-09-21 06:23

If I understood well, you open ActivityB from ActivityA, and then ActivityC from ActivityB. You want ActivityA to get values from ActivityC.

Probably the easiest way is to store the values as static, and read them directly from the class.

If you want to use StartActivityForResult (so you can get the results from onActivityResult), you should make ActivityB receive the results from C, and then make ActivityB pass the results to ActivityA:

ActivityA implements ResultsReciever. Then start Activity B, and retrieve the calling activity (ActivityA) with

interface ResultsReciever{
    executeSomething(ArrayList values);
}

Declare ActivityA implementing the interface:

public class ActivityA extends Activity implements ResultsReciever

On Activity B, at the onStart method:

ResultsReciever caller = (ResultsReciever)getCallingActivity();

Then ActivityB starts ActivityC with StartActivityForResult(). In the onActivityResult in ActivityB you can call then:

caller.executeSomething(whatever);
查看更多
登录 后发表回答