I am reading data from a REST server. on occasion I am getting very long delays, but after the communication:
protected JSONObject doInBackground(String... params)
...
HttpResponse response;
client = new DefaultHttpClient();
...
HttpPost post = new HttpPost(sendURL);
StringEntity se = new StringEntity( postJSON.toString(), "UTF-8");
Log.d(getClass().getName(), String.format("post object: %s", postJSON.toString()));
se.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
post.setEntity(se);
response = client.execute(post);
Log.d(getClass().getName(), "Response received");
if(response!=null){
String responseStr = null;
if (response.getStatusLine().getStatusCode() == 200){
try {
Log.d(getClass().getName(), "Response status OK");
responseStr = EntityUtils.toString(response.getEntity());
Log.d(getClass().getName(), "Response String read: "
...
At random intervals the task takes a very long time to complete, creating an unacceptable user experience. The timestamps in the log indicate that the call to response.getEntity() is taking a very long time, 30 seconds and more. Questions such as this indicate that the call to getEntity() does in fact involve network communication. Is this the case? Or is the delay happening because the AsyncTask is not getting resources?