ARouter fragment onActivityResult StartActivityForResult

参考:

ARouter fragment onActivityResult

ARouter路由框架不回调onActivityResult的问题

A_activity 的【fragment】中:

@Override
public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
    mItemClickBean = (ApprovalInfoRepoBean.RowsBean) adapter.getItem(position);
    if (mItemClickBean == null) {
        return;
    }
    this.mOnItemClickPosition = position;

    Postcard postcard = ARouter.getInstance()
            .build(BizApi.PATH_DETAIL_APPROVAL)
            .withLong("lot_number", mItemClickBean.getLotNumber())
            .withString("approval_note", mItemClickBean.getApproveNote());
    LogisticsCenter.completion(postcard);
    Intent intent = new Intent(getActivity(), postcard.getDestination());
    intent.putExtras(postcard.getExtras());
    startActivityForResult(intent, 100);					//跳转,code要大于0

}

@Override
public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (mItemClickBean == null) {
        return;
    }
    if (requestCode == 100 && resultCode == 200) {			//返回
        if (data != null) {
            boolean actionAgree = data.getBooleanExtra("action_agree", false);
            if (actionAgree) {
                mItemClickBean.setApproveStatus(2);
                mAdapter.notifyItemChanged(mOnItemClickPosition);
            } else {
                mItemClickBean.setApproveStatus(3);
                mAdapter.notifyItemChanged(mOnItemClickPosition);
            }
        }
    }
}

B_activity 中:

@Override
public void agreeSuccess() {
    Intent intent = new Intent();
    intent.putExtra("action_agree", true);
    setResult(200, intent);
    finish();
}

@Override
public void rejectSuccess() {
    Intent intent = new Intent();
    intent.putExtra("action_agree", false);
    setResult(200, intent);
    finish();
}

你可能感兴趣的:(ARouter fragment onActivityResult StartActivityForResult)