One consideration though, if i am not wrong, AsyncTasks need to be executed
from the UIThread.

Regarding your code, put the part in which the HTTP Request is sent and the
response is got in "line" in the "doInBackground" method of the AsyncTask
so that it runs on the background thread and does not block any execution
on the UIThread, and in "postExecute" method, return  'line' and process is
as you may

On Wed, Feb 1, 2012 at 1:14 PM, madlymad <mando7s...@gmail.com> wrote:

> here is a good example of Asynctask usage!
>
>
> http://www.androidsnippets.com/grab-a-url-source-with-progressdialog-and-asynctask
>
> On Jan 31, 3:24 pm, aashutosh <aashutosh.andr...@gmail.com> wrote:
> > 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+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
>

-- 
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+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to