title: Android AsynchTask inside IntentService
body: <p>I'm trying to run a asynchronous task inside the IntentService for downloading a file. However when I start the downloading thread, I get the following warning, and the process doesn't proceed.</p>
  
  <pre><code>W/MessageQueue(10371): java.lang.RuntimeException: Handler{406ee8f8} sending message to a Handler on a dead thread
  </code></pre>
  
  <p>I searched about this issue, and found that it's likely to have something to do with Handler and Looper of Pipeline Threading. The cause might be that the process of the thread to download a file is passed to the Handler of IntentService which dies soon after finishing its process. I know the thread should be passed to the Handler of the main thread (UI thread), not IntentService.
  Some people are saying that writing the following code in MainActivity class or Application class's onCreate() works, in order to pass the thread to proper Handler (Handler of main thread),</p>
  
  <pre><code>Class.forName("name.of.class.doing.asynch.task");
  </code></pre>
  
  <p>, but didn't work for me.</p>
  
  <p>Let me give you details about my code and libraries I'm using.</p>
  
  <h3>- IntentService </h3>
  
  <p>Extending the class GCMBaseIntentService of "Google Cloud Messaging" (http://developer.android.com/guide/google/gcm/index.html). The error above occurs after Log.i(TAG, "STARTING CONNECTION") on LogCat.</p>
  
  <pre><code>public class GCMIntentService extends GCMBaseIntentService{
  
      public GCMIntentService() {
          super(Environment.GCM_SENDER_ID);
      }
  
      @Override
      protected void onMessage(Context context, Intent intent) {
          String[] allowedContentTypes = new String[] { "image/jpeg" };
          Log.i(TAG, "STARTING CONNECTION");
          AsynchConnector.getForBinaryResponse("MY_URL", new BinaryHttpResponseHandler(allowedContentTypes){
              @Override
              public void onSuccess(byte[] imageData) {
                  Log.i(TAG, "SUCCESS!!");
          });
      }
  
      (... @Override methods follows)
   }
  </code></pre>
  
  <h3>- Thread to download a file</h3>
  
  <p>Using "Android Asynchronous Http Client" (http://loopj.com/android-async-http/) which facilitates asynchronous http connection.</p>
  
  <pre><code>public class AsynchConnector{                                                                                                                                                 
      private static final String BASE_URL = Environment.SERVER_URL;
      private static AsyncHttpClient client = new AsyncHttpClient();
  
      public static void getForBinaryResponse(String url, BinaryHttpResponseHandler binaryHttpResponseHandler){
          client.get(getAbsoluteUrl(url), binaryHttpResponseHandler);
      }
  }
  </code></pre>
  
  <h3> Application's onCreate()</h3>
  
  <pre><code>class MyApp extends Application{
      @Override
      onCreate(){
          try {                                                                                                                                                                 
              Class.forName("com.myapp.AsynchConnector");
          } catch (ClassNotFoundException e) {
              e.printStackTrace();
          }
      }
  }
  </code></pre>
  
  <p>How can I make this work? Please help me!</p>