startActivityForResult重要用来从FirstActivity跳转到SecondActivity而后归来FirstActivity而且获得从SecondActivity传回顾的参数。

运用本领:如次从ClockManagerActivity跳转到NewMapActivity而且传address值

ClockManagerActivity:

Intent intent = new Intent(ClockManagerActivity.this,NewMapActivity.class);

intent.putExtra("address",position);

startActivityForResult(intent,3);

当乞求码为3且截止码为RESULT_OK时,获得从NewMapActivity传过来的position值

@Override

protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {

super.onActivityResult(requestCode, resultCode, data);

if (requestCode == 3 && resultCode == RESULT_OK) {

// SearchAddressInfo info = (SearchAddressInfo) data.getParcelableExtra("position");

String position = data.getStringExtra("position");

mTvClockInAddress.setText(position);

}

}

NewMapActivity:

获得从ClockManagerActivity传过来的address值

String position = getIntent().getStringExtra("address");

树立resultCode码,传播position参数,封闭暂时Activity

Intent intent = getIntent();

String s = addressInfo.addressName + addressInfo.title;

intent.putExtra("position", s);

setResult(RESULT_OK,intent);

finish();