Android Activity利用setResult赋值

//传值
getIntent().putExtra("useraddress",userAddressBeanList.get(position));
//必须在finish()前调用,否则10的resultCode会默认成为0
setResult(10,getIntent());
finish();

接收的区域复写:

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 2 && resultCode == 10) {
            userAddressBean = (UserAddressBean) data.getSerializableExtra("useraddress");
   
        }
    }

requestCode为Activity跳转时传的值:

startActivityForResult(new Intent(this, AddressManagementListActivity.class), requestCode);

resultCode为setResult传的值:

setResult(resultCode,Intent());

©️2020 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客 返回首页