从android中的活动返回一个arraylist

5 android

我有两个活动,例如活动1和活动2.活动1将调用活动2并发送一个arraylist,然后将其修改.我已经使用了一个意图.我现在想要做的是,当活动2调用finish()时,我希望将修改后的arraylist发送回活动1,以便它具有该arraylist的最新版本.

活动1:

Bundle b = new Bundle();
b.putParcelableArrayList("com.Woody.RingerSchedule", schedules);
Intent i = new Intent(this, addSchedule.class);
i.putExtras(b);
startActivity(i);
Run Code Online (Sandbox Code Playgroud)

目前为止的活动2:

Bundle b = getIntent().getExtras();
final ArrayList<Schedule> schedules = b.getParcelableArrayList("com.Woody.RingerSchedule");
//modify arraylist
//need code here to return arraylist to activity 1
finish();
Run Code Online (Sandbox Code Playgroud)

任何帮助赞赏.

Pen*_*m10 6

你需要setResult使用Intentparam 调用

Intent intent = new Intent();
intent.putExtra("returnKey","test");
setResult(RESULT_OK,intent);
finish();
Run Code Online (Sandbox Code Playgroud)

您从启动活动的活动中读取 startActivityForResult

//we need a handler for when the secondary activity finishes it's work
//and returns control to this activity...
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent){
    super.onActivityResult(requestCode, resultCode, intent);
    Bundle extras = intent.getExtras();
    mEditText1.setText(extras != null ? extras.getString("returnKey"):"nothing returned");
}
Run Code Online (Sandbox Code Playgroud)

有关更多示例,请参阅此示例:http://www.remwebdevelopment.com/dev/a33/Passing-Bundles-Around-Activities.html