title: Activity Freezes on Particular JSON response in onPostExecute method
body: <p>In my application I am having an activity which is responsible for displaying results in lists by fetching data from remote server in JSON format. but when ever data is returned from server my activity freezes on a particular response. i.e status_code=-1 which is stored in <strong>jsonResult</strong> variable but when ever the server returns other status codes it works fine.</p>
  
  <p>For Example Two response Messages from server</p>
  
  <pre><code>{"user_data":[],"status_message":"ERROR","status_code":-1}
  {"user_data":[{"booked_slots":"1","slot_no":"2","place_name":"Centaurus","person_name":"faisal","slot_status":"Reserved","vehicle_no":"abc","startTime":"2","endTime":"3"}],"status_message":"OK","status_code":1}
  </code></pre>
  
  <p>whenever status_code=-1 is returned the activity freezes with round wait pointer saying please wait and doesn't proceed further.</p>
  
  <p><strong>AsyncTask Code:</strong></p>
  
  <pre><code>    private class AsyncDataClass extends AsyncTask&lt;String, Void, String&gt; {
  
          @Override
  
          protected String doInBackground(String... params) {
  
              String responseBody = "";
  
              HttpParams httpParameters = new BasicHttpParams();
              HttpConnectionParams.setConnectionTimeout(httpParameters, 5000);
              HttpConnectionParams.setSoTimeout(httpParameters, 5000);
              HttpClient httpClient = new DefaultHttpClient(httpParameters);
              HttpPost httpPost = new HttpPost(params[0]);
              String jsonResult = "";
              try {
  
                  HttpResponse response = httpClient.execute(httpPost);
                  jsonResult = inputStreamToString(response.getEntity().getContent()).toString();
                  System.out.println("Returned Json object " + jsonResult.toString());
              } catch (ClientProtocolException e) {
  
                  e.printStackTrace();
              } catch (IOException e) {
                  e.printStackTrace();
              }
              return jsonResult;
          }
  
          @Override
          protected void onPreExecute() {
              super.onPreExecute();
              pDialog = new ProgressDialog(ShowSlots.this);
              pDialog.setMessage("Please wait...");
              pDialog.setCancelable(true);
              pDialog.show();
          }
  
          @Override
  
          protected void onPostExecute(String result) {
  
              super.onPostExecute(result);
              System.out.println("Resulted Value: " + result);
              if(result.equals("") || result == null){
                  Toast.makeText(ShowSlots.this, "Server connection failed", Toast.LENGTH_LONG).show();
                  return;
              }
              int jsonResult = returnParsedJsonObject(result);
              if(jsonResult == -1){
                  Toast.makeText(ShowSlots.this, "ALL Slots Are Available", Toast.LENGTH_LONG).show();
  return;
              }
              if(jsonResult == 1){
                  Toast.makeText(ShowSlots.this, "Got Parking Spots", Toast.LENGTH_LONG).show();
                  try {
                      JSONObject jsonObj = new JSONObject(result);
                      // Getting JSON Array node
                      parkings = jsonObj.getJSONArray("user_data");
                      // looping through All Contacts
                      for (int i = 0; i &lt; parkings.length(); i++) {
                          JSONObject c = parkings.getJSONObject(i);
                          String slot = c.getString(TAG_SLOT);
                          serverReturn.add(slot);
                      }
  
                      rts= new ArrayList&lt;slots&gt;();
                      String status="";
                      int counter = 1;
                         for(int i=0;i&lt;availableParkings;i++){
  
                             for(int j = 0; j&lt;serverReturn.size();j++){
  
                                  if(counter==Integer.parseInt(serverReturn.get(j))){
                                      status="Reserved";
                                      break;
                                  }
                                 else{
                                      status="Available";
                                  }
  
                             }
                             rts.add(new slots(parkingName, counter, status));
                             counter++;
                        }
  
                       refreshDisplay();
  
                  } catch (JSONException e) {
                      e.printStackTrace();
                  }
  
  
                  if (pDialog.isShowing())
                      pDialog.dismiss();
  
  
              }
  
          }
  
          private StringBuilder inputStreamToString(InputStream is) {
              String rLine = "";
              StringBuilder answer = new StringBuilder();
              BufferedReader br = new BufferedReader(new InputStreamReader(is));
              try {
                  while ((rLine = br.readLine()) != null) {
                      answer.append(rLine);
                  }
              } catch (IOException e) {
  // TODO Auto-generated catch block
                  e.printStackTrace();
              }
              return answer;
          }
      }
  </code></pre>