我有2個Web服務方法在AsyncTask中被調用。第一個被成功調用,但第二個Web服務方法未被調用。任何想法如何在第一個之後調用第二個方法?onPostExecute()方法不被執行
的AsyncTask代碼
public class Transaction extends AsyncTask<String,Void,String>
{
private String finalBalance1 = "", price1 = "", pName = "", pNric = "", pClass = "", sno = "";
public Transaction(String price1, String pName, String pNric, String pClass, String sno, String finalBalance1)
{
super();
this.finalBalance1 = Double.toString(finalBalance);
this.price1 = Double.toString(sPrice);
this.pName = sRA.studentName;
this.pNric = sRA.studentNric;
this.pClass = sRA.studentClass;
this.sno = logger.stallNo;
}
@Override
protected String doInBackground (String...url)
{
String result = "";
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://152.226.152.175/NCO/WebService.asmx/InsertStudentTransaction");
try
{
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(5);
nameValuePairs.add(new BasicNameValuePair("NRIC", pNric));
nameValuePairs.add(new BasicNameValuePair("Name", pName));
nameValuePairs.add(new BasicNameValuePair("Class", pClass));
nameValuePairs.add(new BasicNameValuePair("StallNo", sno));
nameValuePairs.add(new BasicNameValuePair("AmountSpent", price1));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
InputStream in = entity.getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(in, "UTF-8"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null)
{
result = line;
}
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return result;
}
protected void onPostExecute (String result)
{
if(result != null)
{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://152.226.152.175/NCO/WebService.asmx/UpdateParticulars");
try
{
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(4);
nameValuePairs.add(new BasicNameValuePair("NRIC", pNric));
nameValuePairs.add(new BasicNameValuePair("FixedAmount", finalBalance1));
nameValuePairs.add(new BasicNameValuePair("Name", pName));
nameValuePairs.add(new BasicNameValuePair("Class", pClass));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
InputStream in = entity.getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(in, "UTF-8"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null)
{
System.out.println(line);
}
} catch (ClientProtocolException e) {
e.printStackTrace();
}catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
@覆蓋它.. – KOTIOS
哪裏'Transaction.execute();'? –
我已經在我的按鈕的onclicklistener –