title: How to cancel DefaulHttpClient execution process in multithread
body: <p>I am developing an android application that rely very much on internet, I retrieve data frequently using this <a href="http://pastebin.com/dpmk8B9h" rel="nofollow">RestClient Class</a>, that wrap some detail on using DefaultHttpClient to do network request.</p>
  
  <p>And I always use different thread to do the HTTP request, I create a class like this:</p>
  
  <pre><code>public class AsyncWorker {
  
      final String SERVER_URL = "http://api.blabla.com";
      RestClient client = new RestClient();
  
      public void requestHttp(final String url, final ArrayList&lt;NameValuePair&gt; params, final RequestListener listener) {
          new Thread(new Runnable() {
  
              public void run() {
                  try {
                      client.setUrl(url);
                      client.setParams(params);
                      client.Execute(RestClient.RequestMethod.POST);
                      String response = client.getResponse();
                      listener.onComplete(response);
                  } catch (Exception ex) {
                      Log.d("LOGIN", ex.getMessage());
                  }
              }
          }).start();
      }
      etc...
  </code></pre>
  
  <p>So whenever I need to do a HTTP request, I only need to create <code>AsyncWorker</code> object, and provide the <code>RequestListener</code> callback interface.</p>
  
  <p>But the problem is, how can I cancel the HTTP Request when the user press the <strong>back/cancel button</strong>? and in this case the application still is in one activity, for example I create a dialog, and the user do a request from that dialog, and then back button pressed, the dialog dismissed, and I need to cancel the request on that time.</p>