title: What is the most efficient way on Android to call HTTP Web API calls that return a JSON response?
body: <p>I'm the perfectionist type, I already got web API calls working fine with Google Places API (just as an example), but I feel it's sometimes slow or maybe I'm not doing it right. Some blogs are saying I should use AndroidHttpClient, but I'm not, should I ?</p>
  
  <p>The web API calls i'm using return json and I don't run them on the UI thread, hence using AsyncTask (is AsyncTask the most efficient way to run on background thread or should I use something else ?)</p>
  
  <p>Please see my code and tell me how could it be more efficient in anyway</p>
  
  <pre><code>public static class NearbySearchRequest extends AsyncTask&lt;String, Void, JSONObject&gt;
  {
      Exception mException = null;
  
      @Override
      protected void onPreExecute()
      {
          super.onPreExecute();
          this.mException = null;
      }
  
      @Override
      protected JSONObject doInBackground(String... params)
      {
          StringBuilder urlString = new StringBuilder();
          urlString.append("https://maps.googleapis.com/maps/api/place/nearbysearch/json?");
          urlString.append("key=").append(Constants.GOOGLE_SIMPLE_API_KEY);
          urlString.append("&amp;location=").append(params[0]);
          urlString.append("&amp;sensor=").append("true");
          urlString.append("&amp;language=").append("en-GB");
          urlString.append("&amp;name=").append(params[1]);
          urlString.append("&amp;rankby=").append("distance");
  
          LogHelper.Log(urlString.toString());
  
          HttpURLConnection urlConnection = null;
          URL url = null;
          JSONObject object = null;
  
          try
          {
              url = new URL(urlString.toString());
              urlConnection = (HttpURLConnection) url.openConnection();
              urlConnection.setRequestMethod("GET");
              urlConnection.setDoOutput(true);
              urlConnection.setDoInput(true);
              urlConnection.connect();
              InputStream inStream = null;
              inStream = urlConnection.getInputStream();
              BufferedReader bReader = new BufferedReader(new InputStreamReader(inStream));
              String temp, response = "";
              while ((temp = bReader.readLine()) != null)
                  response += temp;
              bReader.close();
              inStream.close();
              urlConnection.disconnect();
              object = (JSONObject) new JSONTokener(response).nextValue();
          }
          catch (Exception e)
          {
              this.mException = e;
          }
  
          return (object);
      }
  
      @Override
      protected void onPostExecute(JSONObject result)
      {
          super.onPostExecute(result);
  
          if (this.mException != null)
              ErrorHelper.report(this.mException, "Error # NearbySearchRequest");
      }
  }
  </code></pre>