title: start service from activity and wait until its ready
body: <p>I want to start a Service from an Activity.</p>
  
  <p>First I tried it with a LocalBinder. This works, but the service was bound to the activity. I don't want to stop the service when the activity is gone. I found no solution with the LocalBinder so I removed it and tried this:</p>
  
  <p>use a singleton instance in the service
  call the startService methode in a new thread and waits until the instance is available:</p>
  
  <pre><code>final Intent recordService = new Intent(RecordActivity.this, RecordService.class);
      Runnable r = new Runnable() {
          @Override
          public void run() {
              startService(recordService);
          }
      };
      new Thread(r).start();
  
      Log.i(MMLF.T, "service instance: "+serviceInstance);
      final ProgressDialog mProgressDialog = ProgressDialog.show(
              RecordActivity.this, "Waiting", "wait until record service is loaded",
              true);
      while (serviceInstance == null) {
          serviceInstance = RecordService.get();
          try {
              Thread.sleep(1000);
          } catch (InterruptedException e) {
              Log.e(MMLF.T, "could not sleep", e);
          }
      }
      mProgressDialog.dismiss();
  </code></pre>
  
  <p>But this doesn't work, too. It stucked in the waiting loop. If I remove this waiting stuff and the new <code>new Thread(r).start()</code> line is the last, the activity and service start fine.</p>
  
  <p>How to start a service independent from an activity? I also let them to communicate with each other. The activity should call two methods (start and stop recording) and the service should send messages. For the second I can use LocalBroadcast.</p>