这是soap web Service的示例代码。但它太慢了。如何改进和优化代码以加快响应速度?
private class Query extends AsyncTask<String, Integer, Boolean> {
ProgressDialog PD = new ProgressDialog(Products.this);
@Override
protected void onPreExecute() {
super.onPreExecute();
PD.setMessage("plec...");
PD.setProgressStyle(ProgressDialog.STYLE_SPINNER);
PD.show();
}
@Override
protected Boolean doInBackground(String... params) {
sp_cod_anbar = getSharedPreferences("cod", 0);
String cod_and = sp_cod_anb.getString("cod", "0");
boolean resul = true;
final String NAMESPACE = "http://tempuri.org/";
final String URL = "";
final String METHOD_NAME = "";
final String SOAP_ACTION = "";
SoapObject requste = new SoapObject(NAMESPACE, METHOD_NAME);
requste.addProperty("com", cod);
requste.addProperty("cat", Id);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(requste);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.setXmlVersionTag("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
androidHttpTransport.debug = true;
try {
androidHttpTransport.call(SOAP_ACTION, envelope);
SoapObject result = (SoapObject) envelope.getResponse();
Log.d("RESULT", "" + result);
int cols = result.getPropertyCount();
prgmNameList = new String[cols];
prgmEm = new String[cols];
prgmmo = new String[cols];
prgmGht = new String[cols];
prgmImages = new String[cols];
for (int i = 0; i < cols; i++) {
Object objectResponse = (Object) result.getProperty(i);
SoapObject r = (SoapObject) objectResponse;
prgmNameList[i] =r.getProperty("Kala").toString();
prgmEm [i] = r.getProperty("Em").toString();
prgmmo [i] = r.getProperty("Mo").toString();
prgmGht [i] = r.getProperty("Ght").toString();
prgmImages [i] = r.getProperty("Ax").toString();
}
} catch (Exception e) {
String err = (e.getMessage() == null) ? "SD Card failed" : e.getMessage();
Log.e("sdcard-err2:", err);
resul = false;
}
return resul;
}
@Override
protected void onPostExecute(Boolean result) {
if (result) {
adapter = new MainListAdapter(Productst.this, prgmNameList, prgmEm ,prgmmo ,prgmGht ,prgmImages );
listView_products.setAdapter(adapter);
PD.dismiss();
} else {
PD.dismiss();
Intent in = new Intent(Products.this, ErrorConnection.class);
startActivity(in);
}
} }
答案 0 :(得分:0)
Object objectResponse = (Object) result.getProperty(i);<br>
SoapObject r = (SoapObject) objectResponse;
SoapObject r = (SoapObject) result.getProperty(i);