title: Android, can I put AsyncTask in a separate class and have a callback?
body: <p>I'm just learning about AsyncTask and want to use it as a separate class, rather then a subclass.</p>
  
  <p>For example, </p>
  
  <pre><code>class inetloader extends AsyncTask&lt;String, Void, String&gt; {
  
  
      @Override
      protected String doInBackground(String... urls) {
  
          String response = "";
  
              DefaultHttpClient client = new DefaultHttpClient();
              HttpGet httpGet = new HttpGet(urls[0]);
              try {
                  HttpResponse execute = client.execute(httpGet);
                  InputStream content = execute.getEntity().getContent();
  
                  BufferedReader buffer = new BufferedReader(
                          new InputStreamReader(content));
                  String s = "";
                  while ((s = buffer.readLine()) != null) {
                      response += s;
                  }
  
              } catch (Exception e) {
                  e.printStackTrace();
              }
  
          return response;
      }
  
  
      @Override
      protected void onPostExecute(String result) {
          Log.e("xx",result);
          // how do I pass this result back to the thread, that created me?
      }
  
  
  }
  </code></pre>
  
  <p>and the main(ui) thread:</p>
  
  <pre><code>inetloader il = new inetloader();
  il.execute("http://www.google.com");
  //il.onResult()
  //{
      ///do something...
  //}
  </code></pre>
  
  <p>Thanks!</p>