嗨,我想知道如何并行运行多个 web 服务调用,实际情况是当我的应用程序第一次启动时,我必须调用 4 个不同的 web 服务并填充数据库,然后用户才能与我的应用程序交互。有人可以建议这样做的最佳方法是什么。还有如何使用 AsyncTask 来运行这 4 个网络服务调用。
截至目前,我正在使用异步任务在我的 homeActivty 中进行一次网络服务调用
new DownloadJSON(HomeActivity.this).execute();
public class DownloadJSON extends AsyncTask<Void, Void, Void> {
private static Context context;
public DownloadJSON(Context context){
this.context = context;
}
@Override
protected Void doInBackground(Void... params) {
try {
startWebServiceData();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null
}
void startWebServiceData() throws IOException {
String URL = "xxxxxxxxxxxx";
String SOAP_NAMESPACE = "xxxxxxxxxxxx";
String METHOD_NAME = "xxxxxxxxxxx";
String SOAP_ACTION = "xxxxxxxxxxxx";
SoapObject soapObject;
soapObject = new SoapObject(SOAP_NAMESPACE, METHOD_NAME);
SoapSerializationEnvelope envp = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envp.dotNet = true;
envp.setOutputSoapObject(soapObject);
System.out.println("soapObject===>"+envp.bodyOut);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try {
androidHttpTransport.call(SOAP_ACTION, envp);
SoapPrimitive response = (SoapPrimitive)envp.getResponse();
String result = response.toString();
System.out.println("response data from server====="+result);
parseJson(result);
} catch (Exception e) {
}}
private static void parseJson(String result) {
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
有人能指出我正确的方向吗