当我的用户点击登录按钮时,我想打我的web服务。我有下面的代码来做到这一点。未被调用:onPostExecute
public void onClick(final View view) {
String orgKey = inputCompany.getText().toString();
new getAppInfo().execute("http://example.webservice.com");
这是我getAppInfo
private class getAppInfo extends AsyncTask<String, Void, String> {
/** The system calls this to perform work in a worker thread and
* delivers it the parameters given to AsyncTask.execute() */
@Override
protected String doInBackground(String... urls) {
String xml = null;
try {
// defaultHttpClient
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(urls[0]);
HttpResponse httpResponse = httpClient.execute(httpGet);
HttpEntity httpEntity = httpResponse.getEntity();
xml = EntityUtils.toString(httpEntity);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
// return XML
return xml;
}
/** The system calls this to perform work in the UI thread and delivers
* the result from doInBackground() */
@Override
protected void onPostExecute(String result) {
Document doc = GetDomElement(result); // getting DOM element
NodeList nl = doc.getElementsByTagName("details");
getChildElements(nl);
}
的doBackground
正在运行,但onPostExecute
不是。我已经将它从点击中移出,它已经工作,但我需要它在onClick中。
我如何获得它在我的onClick中运行onPostExecute
?
如果这个选项很大,你可能也会得到一个OutOfMemoryError - 你也可以在Android中捕获它(与Java不同) – siliconeagle
另外,请确保你的清单中有Internet权限 – siliconeagle
感谢您的建议 – BigT