title: Is it possible to use AsyncTask in a Service class?
body: <p>Everything is in the title.</p>
  
  <p>On the official documentations it is stated that <code>Note that services, like other application objects, run in the main thread of their hosting process</code> and AsyncTask only works if it is executed in the UIThread.</p>
  
  <p>So is it possible to use AsyncTask in a Service class?</p>
  
  <p>I am trying to do so but I'm always getting the same error </p>
  
  <pre><code>05-01 18:09:25.487: ERROR/JavaBinder(270): java.lang.ExceptionInInitializerError
  </code></pre>
  
  <p>...</p>
  
  <pre><code>05-01 18:09:25.487: ERROR/JavaBinder(270): Caused by: java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
  </code></pre>
  
  <p>Am I doing something wrong or is this just impossible ?</p>
  
  <p>Here is the code of my Service class</p>
  
  <pre><code>package com.eip.core;
  
  import android.app.Service;
  import android.content.Intent;
  import android.os.AsyncTask;
  import android.os.IBinder;
  import android.os.RemoteException;
  import android.util.Log;
  
  public class NetworkService extends Service {
  
  
      private final INetwork.Stub mBinder = new INetwork.Stub() {
  
          @Override
          public int doConnect(String addr, int port) throws RemoteException {
              new ConnectTask().execute("test42");
              return 0;
          }
      };
  
      @Override
      public IBinder onBind(Intent arg0) {
          return mBinder;
      }
  
      private class ConnectTask extends AsyncTask&lt;String, Void, Void&gt; {
  
          @Override
          protected void onPreExecute() {
              super.onPreExecute();
              Log.i("OnPreExecute()", "");
          }
  
          @Override
          protected Void doInBackground(String... arg0) {
              Log.i("doInBackground()", "");
              return null;
          }
  
          @Override
          protected void onPostExecute(Void result) {
              super.onPostExecute(result);
              Log.i("OnPostExecute()", "");
          }
  
      }
  }
  </code></pre>