Activity返回数据给上一个活动

1.在A这个Activity中以startActivityForResult(intent, requestCode)启动B这个Activity


2.在B这个Activity中
setResult(resultCode, intent);
finish();
结束活动


3.重写A这个Activity的onActivityResult(int requestCode, int resultCode, Intent data)方法来处理数据
如:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case 1:
if (resultCode == RESULT_OK) {
String returnedData = data.getStringExtra("data_return");
Log.d("FirstActivity", returnedData);
}
break;
default:
break;
}
}

posted @ 2017-04-15 17:56  rorshach  阅读(634)  评论(0编辑  收藏  举报