I am new to async task . I need to use httppost in my application. Please help me to manipulate the following code using async task. Please give me structured code
HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost("url here");
httpPost.addHeader("Content-Type", "application/xml");
try {
HttpResponse response = httpClient.execute(httpPost);
BufferedReader reader = new BufferedReader(
new InputStreamReader(response.getEntity()
.getContent(), "UTF-8"));
StringBuffer responseString = new StringBuffer("");
String line;
while ((line = reader.readLine()) != null) {
responseString.append(line);
}
System.out.println("respose QQQQQQQQQQQ");
System.out.println("11response "
+ responseString.toString());
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
see this http://developer.android.com/reference/android/os/AsyncTask.html. In doInBackground() method write your code for manipulating HTTP Post.In preexecute() handle UI before running thread and in onPostExecute() handle UI after thread completed.Don’t write UI releated code in doinBackground().
call AsynTask thread as follows
SerivceCalling class: