首页 > 解决方案 > 在另一个异步任务中执行异步任务

问题描述

我正在尝试在 OnPostExecute 中调用另一个异步任务。第二个任务似乎根本没有运行。我无法从日志中打印任何内容。

@Override
protected void onPostExecute(String result) {
        super.onPostExecute(result);

        try {
            JSONObject json = new JSONObject(result);
            JSONArray lignes = json.getJSONArray("lignes");
            populatelist(lignes);
        }
        catch (JSONException e) {

        }
    }
}

populatelist 函数填充一个数组。在这个函数中,我尝试调用第二个异步任务来获取基于这个列表的值。

 protected void populatelist(JSONArray lignes){
    try {
        for(int i=0;i<lignes.length(); i++) {
            JSONObject jsonas = lignes.getJSONObject(i);
            String fdesignation = jsonas.getString("designation");
            String fqtecde = jsonas.getString("qtecde");
            String fcode_produit = jsonas.getString("code");
            InfoStock(fcode_produit);
            items.add(new PickingListProduitItem(fdesignation,"",fqtecde, ""));

        }
    }
    catch(Exception e){

    }
}

InfoStock() 是用于从 Web 服务返回附加信息的函数。

 protected void InfoStock(String code_produit){
    String stockURL = "http://" + mSharedPreferences.getString(Constants.SERVER_IP,"")+"//rest/v2/produit/info/code/"+ code_produit + "?stock=true";
    try {
        if (mDownloader != null && mDownloader.getStatus() == AsyncTask.Status.RUNNING) {
            mDownloader.cancel(true);
            mPDialog.dismiss();
        }
        mPDialog = new ProgressDialog(getApplicationContext());
        mDownloader = new XMLDownloader(getApplicationContext(),mPDialog);
        byte[][] downloadResults = mDownloader.execute(stockURL).get();

        // Read stock info.
        String s = new String(downloadResults[0], StandardCharsets.UTF_8);
        JSONObject resp = new JSONObject(s);
        PrixStockJSONParser psj = new PrixStockJSONParser(resp);
        mRepInfoStock = psj.getRepInfoStock();
        mRepInfoPrix = psj.getRepInfoPrix();


    } catch (Exception ex) {

    }
}

我正在尝试在OnPostExecute方法中创建的数组 <> 中设置一个值。但是没有,并且根本没有error message填充数组。即使我尝试从该函数打印日志,它也不会执行任何操作。InfoStock

欢迎任何建议。

标签: javaandroidandroid-asynctask

解决方案


推荐阅读