title: Android startService() takes a long time to return to UI thread
body: <p>my usecase is (roughly) the following on first startup:</p>
  
  <ol>
  <li>activity starts a service</li>
  <li>service gets and saves data in a database</li>
  <li>service notifies activity with an intent</li>
  <li>activity displays data</li>
  </ol>
  
  <p>Now I want to display a progress bar while the service is busy. The problem is:</p>
  
  <p><code>startService(new Intent(getApplicationContext(), UpdateDataService.class));</code></p>
  
  <p>takes a very long time to "come back" to the UI thread. It seems to be a synchronized function (or <a href="https://stackoverflow.com/questions/5085190/android-startservice-synchronous">not</a>?). If a empty the service class the startService command is processed almost instant. It seems the UI thread waits for the Serice to handle its work, which does not make sense at all. I tried to start (as stupid as it may seem) to start the service a async task while displaying a progress bar in my UI thread. Weird enough this works sometimes. Othertimes I just get a white screen while my service is working and afterwards for a millisecond ma progressbar and then my UI. </p>
  
  <p>Now my question: How do I start the service without blocking my UI?</p>
  
  <pre><code>public class MyClass extends TabActivity {
  private ProgressDialog pd;
  
  @Override
  public void onCreate(final Bundle savedInstanceState) {
  
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
  
      Intent intent = null;
  
      //building some tabs here, setting some text views....
  
      // starting service if does not exist yet
      boolean serviceRunning = false;
  
      final ActivityManager manager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
      for (final RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
          if ("aegir.mobile.UpdateDataService".equals(service.service.getClassName())) {
              serviceRunning = true;
              Log.i(MY_APP_TAG, "Service found.");
          }
      }
      if (!serviceRunning) {
          pd = ProgressDialog.show(this, "Loading...", "Setting up data.", true, false);
          new StartServiceAsync().execute("");
      }
  
  }
  
  private final Handler handler = new Handler() {
      @Override
      public void handleMessage(final Message msg) {
          pd.dismiss();
  
      }
  };
  
  public class StartServiceAsync extends AsyncTask&lt;String, Void, String&gt; {
  
      @Override
      protected String doInBackground(final String... params) {
          // starting service
          startService(new Intent(getApplicationContext(), UpdateDataService.class));
          return null;
      }
  
      @Override
      protected void onPostExecute(final String result) {
          handler.sendEmptyMessage(0);
          super.onPostExecute(result);
      }
  }
  </code></pre>