在另一个异步任务中执行异步任务

时间:2020-01-17 12:15:04

标签: java android android-asynctask

我试图在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,并且数组 not 都没有填充。即使我尝试从InfoStock函数打印日志,它也不会执行任何操作。

欢迎提出任何建议。

0 个答案:

没有答案