有异步请求时注意程序执行的顺序

<pre name="code" class="java">正确
 @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if(resultCode == 2){
            moveWork(TestActivity.this,workId);
        }
    }


    /**
     * 移动作品
     */
    public void moveWork(Context context, String workId) {
        Map<String, String> map = new HashMap<>();
        String uid = ApiUtil.getUid();
        map.clear();
        int time = ComplexPreferences.getTime();
        if (time == 0) {
            map.put("time", System.currentTimeMillis() + "");
        } else {
            map.put("time", time + "");
        }
        map.put("work_set_privacy",ComplexPreferences.getWorkSetPrivacy());
        map.put("work_set_id",ComplexPreferences.getWorkSetId());
        map.put("work_id", workId);
        map.put("uid", uid);
        String SIGN = null;
        if (uid.equals("0")) {
            SIGN = ApiUtil.getWithoutTokenSigned(map);
        } else {
            SIGN = ApiUtil.getWithTokenSigned(map);
        }
        map.put("sign", SIGN);
        Log.d("TestActivity", "map:" + map);
        OkHttpClientUtil.postAsyn(IClientUrl.MOVE_WORK, new OkHttpClientUtil.ResultCallback<String>() {
            @Override
            public void onError(Request request, Exception e) {

                L.d(e.toString());
            }

            @Override
            public void onResponse(String response) {
                L.d("moveWork:", response);
                Gson gson = new Gson();
                if (ApiUtil.isSuccess(response, gson)) {
                    To.showShort(context, "移动作品成功");
                    <span style="background-color: rgb(255, 0, 0);">//等移动完成后再执行
                    cDetails(workId);</span>
                } else {
                    To.showShort(context, "移动作品失败");
                }
            }
        }, map);
    }


 

错误:

   @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if(resultCode == 2){
            moveWork(TestActivity.this,workId);
            cDetails(workId);
        }
    }


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值