title: How to add AsyncTask in an HttpURLConnection?
body: <p>I'm establishing a server connection, my problem is that I need to put an <code>AsyncTask</code> on my code, because its not working in sdk version <code>10</code> up. I don't want to use the <code>StrictMode.ThreadPolicy</code>.</p>
  
  <pre><code>public class TestConnection extends Activity {
  
  @Override
  public void onCreate(Bundle cbundle) {
      super.onCreate(cbundle);
  
      ConnectivityManager aConnectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
      NetworkInfo aNetworkInfo = aConnectivityManager.getActiveNetworkInfo();
      if (aNetworkInfo != null &amp;&amp; aNetworkInfo.isConnected()){
          Toast.makeText(this, "Internet Connected", Toast.LENGTH_LONG).show();
      }else{
          Toast.makeText(this, "Internet Connection Timeout", Toast.LENGTH_LONG).show();
      }
  
  
      URL aURL;
      /* Will be filled and displayed later. */
      String aString = null;
  
      /* We will show the data we read in a TextView. */
      TextView aTextView = new TextView(this);
      try {
  
          /* Define the URL we want to load data from. */
          aURL = new URL(
                  "http://url");
  
          /* Open a connection to that URL. */
          final HttpURLConnection aHttpURLConnection = (HttpURLConnection) aURL.openConnection();
  
          /* Define InputStreams to read from the URLConnection. */
          InputStream aInputStream = aHttpURLConnection.getInputStream();
          BufferedInputStream aBufferedInputStream = new BufferedInputStream(
                  aInputStream);
  
          /* Read bytes to the Buffer until there is nothing more to read(-1) */
          ByteArrayBuffer aByteArrayBuffer = new ByteArrayBuffer(50);
          int current = 0;
          while ((current = aBufferedInputStream.read()) != -1) {
              aByteArrayBuffer.append((byte) current);
          }
  
  
          /* Convert the Bytes read to a String. */
          aString = new String(aByteArrayBuffer.toByteArray());
      } catch (Exception aException) {
  
          /* On any Error we want to display it. */
          aString = aException.getMessage();
      }
  
      /* Show the String on the GUI. */
      aTextView.setText(aString);
      this.setContentView(aTextView);
  
  }
  
  }
  </code></pre>