android activity之间传递返回值

activity A,跳转至 Activity B ,A传参数user_name给B,然后B再返回修改后的参数user_name给A

 

首先A传user_name给B

Intent input_B = new Intent(UserInfoActivity.this,ForInputActivity.class);
input_driving_age.putExtra("user_name", "哈哈哈");
startActivityForResult(input_B, INFO_USER_NAME);

 

再B接收A传递过来值:

Intent preIntent = getIntent();
String userName = preIntent.getStringExtra("user_name");

再次,B再回传参数给A

Intent result = new Intent();
result.putExtra("value", value);
setResult(RESULT_OK, result);
finish();

再次,A再接收B返回的值

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        switch (requestCode) {
        case INFO_USER_NAME:
                value_name = data.getStringExtra("value");     //接收到的值
         }   

}

 

你可能感兴趣的:(Activity)