0

我正在处理AsynTask,单个 url 调用AsynTask很好,但我想一个接一个地调用两个 Web 服务AsyncTask,请你发送一些代码或想法。

我的代码:

public class GetInstructionItems extends AsyncTask<String, Void, Boolean> {

    public ProgressDialog myProgressDialog = null;
    private Boolean authenticationResult = false;
    private String LOG = SurgicalHistoryAsynTask.class.getName(); 
    private String responseString = "getInstructionItemsResult";
    JSONObject totalResult;

    protected Boolean doInBackground(String... params) 
    {
        return getRespose(params[0]);
    }

    protected void onPostExecute(Boolean result) {

        myProgressDialog.dismiss();
        if (result) 
        {
            Log.d(LOG, "Response ::result "+result);

        }else{

            showAlertMsg(getString(R.string.response_fail));
        }
    }
    protected void onPreExecute() {

        if (!authenticationResult) {
            myProgressDialog = new ProgressDialog(getActivity());
            myProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
            myProgressDialog.setMessage("loading...");
            myProgressDialog.setCancelable(false);
            myProgressDialog.setProgress(100);
            myProgressDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            myProgressDialog.show();
        }
    }

    private boolean getRespose(String inputUrl){


        return true;
    }
}
4

1 回答 1

0
protected Boolean doInBackground(String... params) 
{
    getRespose(params[0]);
    getRespose(params[1]);
    getRespose(params[2]);
    return true;
}

或者

class Responces
{
     boolean r1, r2, r3;
}


protected Responces doInBackground(String... params) 
{
    Responces r = new Responces();

    r.r1 = getRespose(params[0]);
    r.r2 = getRespose(params[1]);
    r.r3 = getRespose(params[2]);
    return r;
}
于 2012-10-02T13:27:43.410 回答