Tuesday, January 31, 2012

[android-developers] how to use AsyncTask

Hello,

How can i use Asynctask for the following code:


public static String getXML() {

String line = null;

DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost("http://someurl/index.xml");
try {
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
line = EntityUtils.toString(httpEntity);

} catch (UnsupportedEncodingException e) {
line = "<results status=\"error\"><msg>Can't connect to server</
msg></results>";
} catch (MalformedURLException e) {
line = "<results status=\"error\"><msg>Can't connect to server</
msg></results>";
} catch (IOException e) {
line = "<results status=\"error\"><msg>Can't connect to server</
msg></results>";
}

return line;

}

this basicaly gets an xml from the website


Thanks in advance

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate