我有兩個來自soap webservice的方法。我在asyntask中調用它們,它是info.java頁面的超類,並用asyntask的onPost方法獲得結果。 info.java/onCreate的調用代碼如下。如何在同一活動中使用兩種Web服務方法?
try{
PropertyInfo propertyInfo1 = new PropertyInfo();
properties.clear();
propertyInfo1 = new PropertyInfo();
propertyInfo1.setName("Module_id");
propertyInfo1.setType(String.class);
propertyInfo1.setValue(Utils.selectedModule_id);
properties.add(propertyInfo1);
new Info.AsyncTaskService().execute(new ServiceParams("GetInfo", properties), new ServiceParams("GetInfo_Photo", properties));
} catch (Exception e) {
Toast.makeText(Info.this, "Please check your internet connection.", Toast.LENGTH_LONG);
}
這兩種服務方法都採用相同的屬性,這就是爲什麼我給了他們相同的屬性。我的問題是我不能接受結果,因爲我知道它需要在不同的線程中調用這兩個方法,但我不知道如何去做。請問你能幫幫我嗎? asynctask類的代碼也在下面謝謝你。
public class AsyncTaskService extends AsyncTask<ServiceParams, Void, Void> {
String resp = "";
String resp2 = "";
ProgressDialog progressDialog;
@Override
protected Void doInBackground(ServiceParams... params) {
resp = WebService.invoke(params[0].properties, params[0].methodName);
resp2 = WebService.invoke(params[1].properties, params[1].methodName);
return null;
}
@Override
protected void onPostExecute(Void result) {
Log.w("WEBSERVICE RESPONSE===", resp);
Log.w("WEBSERVICE RESPONSE===", resp2);
try {
JSONArray ja = new JSONArray(resp);
Utils.subMenuArrayList.clear();
Info_Item info_item=new Info_Item(ja.getJSONObject(0));
((TextView)findViewById(R.id.txtInfo)).setText(info_item.getInfo());
((TextView)findViewById(R.id.txtModule)).setText(Utils.selectedMenuName);
} catch (JSONException e) {
e.printStackTrace();
}
if (progressDialog != null)
progressDialog.dismiss();
}
@Override
protected void onPreExecute() {
progressDialog = new ProgressDialog(Info.this);
if (progressDialog != null) {
progressDialog.setCancelable(false);
progressDialog.setMessage("İşlem yapılıyor ...");
progressDialog.show();
}
}
protected void onProgressUpdate(Integer... progress) {
if (progressDialog != null)
progressDialog.setProgress(progress[0]);
}
}