Please someone tell me how to make an http post to work in the background using AsyncTask and how to pass AsyncTask parameters? All the examples that I found were not clear enough for me, and they were about to download the file.
I run this code in my main action, and my problem is when the code sends information to the server, the application slows down, as if it was frozen for 2 - 3 seconds, then it continues to work normally until the next send. This post is http sends four variables to the server (book, libadd and time), the fourth is fixed (name)
Thanks in advance
public void SticketFunction(double book, double libadd, long time){ Log.v("log_tag", "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SticketFunction()"); //HttpClient HttpClient nnSticket = new DefaultHttpClient(); //Response handler ResponseHandler<String> res = new BasicResponseHandler(); HttpPost postMethod = new HttpPost("http://www.books-something.com"); try { List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(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("<(.|\n)*?>",""); 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"); } } }
user998582
source share