Android Activity利用setResult赋值

//传值
getIntent().putExtra("useraddress",userAddressBeanList.get(position));
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());

上一篇:Android中的onActivityResult和setResult方法的使用


下一篇:android多层Fragment嵌套,内部Fragment接收不到OnActivityResult()方法的回调的解决方案