我有以下onPostExecute
代码AsyncTask
。它按原样运行良好。但是,当我删除注释的代码时,我从未收到过onPostExecute
事件(没有 Toast)。
@Override
protected void onPostExecute(String result) {
internetData = result;
tempview.append(result + "\n");
Toast.makeText(getApplicationContext(), internetData.toString(), 1).show();
//setServiceId();
}
该setServiceId
事件和后续事件是(故意删除 URL),GetXMLData
是我的AsyncTask
:
public void setServiceId() {
if (internetData != null) {
try {
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
factory.setNamespaceAware(true);
XmlPullParser xpp = factory.newPullParser();
xpp.setInput(new StringReader(internetData));
int eventType = xpp.getEventType();
while (eventType != XmlPullParser.END_DOCUMENT) {
if (eventType == XmlPullParser.TEXT) {
serviceId = xpp.getText();
serviceHistory = "www.google.com/" + serviceId + "/history";
serviceUsage = "www.google.com/" + serviceId + "/usage";
serviceDetails = "www.google.com/" + serviceId + "/service";
Toast.makeText(getApplicationContext(), serviceId, 1).show();
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
updateHistory();
updateDetails();
updateUsage();
}
public void updateHistory() { //Never called
new GetXMLData().execute(serviceHistory);
Toast.makeText(getApplicationContext(), "Update History", 1).show();
}
public void updateUsage() { //Never called
new GetXMLData().execute(serviceUsage);
Toast.makeText(getApplicationContext(), "Update Usage", 1).show();
}
public void updateDetails() { //Never called
new GetXMLData().execute(serviceDetails);
Toast.makeText(getApplicationContext(), "Update Details", 1).show();
}
public void updateData() { //First call
new GetXMLData().execute(serviceListing);
Toast.makeText(getApplicationContext(), "Update Data", 1).show();
}
上面的最后一个事件updateData
被调用,当事件没有被注释掉Toast
时,似乎永远不会消失。setServiceId
除此之外,不会检索 XML 数据。
当它被注释掉时,我收到了updateData()
事件的 XML 数据,但没有后续事件,而且我没有得到Toast
from onPostExecute
。关于为什么会发生这种情况的任何建议?