I'm executing a HTTP Post
from my android device, but for some reason, the post
is executed in few seconds but the screen is still freeze for 18 or 20 seconds more.
The code that I'm using is:
public boolean CommentPost(String comment, String requestId, String deviceId){
List<NameValuePair> params = new ArrayList<NameValuePair>(6);
params.add(new BasicNameValuePair("requestId", requestId));
params.add(new BasicNameValuePair("comment", URLEncoder.encode(requestId)));
params.add(new BasicNameValuePair("deviceId", URLEncoder.encode(deviceId)));
return ExecutePost(params, "Comment/Add");
}
private boolean ExecutePost(List<NameValuePair> params, String url){
String queryString = RewriteParams(params);
url = BaseURL + url + queryString;
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(url);
try {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
httppost.setEntity(new UrlEncodedFormEntity(params));
HttpResponse response = httpclient.execute(httppost);
return true;
} catch (ClientProtocolException e) {
return false;
} catch (IOException e) {
return false;
}
}
I tested the behavior with ajax and some Http clients (like postman) and the request takes less than 1 or 2 second to be executed and get the response. Why it's talking more time in android?