Note that there are some explanatory texts on larger screens.

plurals
  1. POandroid http post asynctask
    text
    copied!<p>Please can anyone tell me how to make an http post to work in the background with AsyncTask and how to pass the parameters to the AsyncTask? All the examples that I found were not clear enough for me and they were about downloading a file.</p> <p>I'm running this code in my main activity and my problem is when the code sends the info to the server the app slows down as if it is frozen for 2 to 3 sec's then it continues to work fine until the next send. This http post sends four variables to the server (book, libadd, and time) the fourth is fixed (name)</p> <p>Thanks in advance </p> <pre><code> public void SticketFunction(double book, double libadd, long time){ Log.v("log_tag", "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SticketFunction()"); //HttpClient HttpClient nnSticket = new DefaultHttpClient(); //Response handler ResponseHandler&lt;String&gt; res = new BasicResponseHandler(); HttpPost postMethod = new HttpPost("http://www.books-something.com"); try { List&lt;NameValuePair&gt; nameValuePairs = new ArrayList&lt;NameValuePair&gt;(5); nameValuePairs.add(new BasicNameValuePair("book", book+"")); nameValuePairs.add(new BasicNameValuePair("libAss", libass+"")); nameValuePairs.add(new BasicNameValuePair("Time", time+"")); nameValuePairs.add(new BasicNameValuePair("name", "jack")); //Encode and set entity postMethod.setEntity(new UrlEncodedFormEntity(nameValuePairs, HTTP.UTF_8)); //Execute //manSticket.execute(postMethod); String response =Sticket.execute(postMethod, res).replaceAll("&lt;(.|\n)*?&gt;",""); if (response.equals("Done")){ //Log.v("log_tag", "!!!!!!!!!!!!!!!!!! SticketFunction got a DONE!"); } else Log.v("log_tag", "!!!!!!!?????????? SticketFunction Bad or no response: " + response); } catch (ClientProtocolException e) { // TODO Auto-generated catch block //Log.v("log_tag", "???????????????????? SticketFunction Client Exception"); } catch (IOException e) { // TODO Auto-generated catch block //Log.v("log_tag", "???????????????????? IO Exception"); } } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload