2012-10-02 41 views
0

我正在致力於AsynTask,來自AsynTask的單個url調用很好,但我想在AsyncTask之後調用兩個Web服務,請問您可以發送一些代碼或想法。Android調用AsyncTask中的多個Web服務

我的代碼:

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; 
    } 
} 
+0

如果 「從AsynTask單一的URL調用是好的」,然後就做twice..and你有兩個網址電話。 – YuviDroid

+0

我們可以從同一個Asynctask調用兩個Web服務調用嗎? – Ravikumar11

回答

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

OR

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; 
}