title: Android, services and threading. Why doesn't the thread start running until other execution ends?
body: <pre><code>public class MyActivity extends Activity 
  {
      /** Called when the activity is first created. */
      @Override
      public void onCreate(Bundle savedInstanceState) {
          Thread myThread = new Thread(){
              public void run()
              {
                  startService(new Intent(BoogerActivity.this, LocalService.class));
              }
          };
          myThread.start();
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);
          while(!LocalService.isRunning);
          System.out.println("Why can't you reach here!?");
      }
  }
  </code></pre>
  
  <p>-</p>
  
  <pre><code>public class LocalService extends Service
  {
      public static boolean isRunning = false;
      IBinder serviceBinder;
      @Override
      public void onCreate()
      {
  
      }
  
      @Override
      public int onStartCommand(Intent intent, int flags, int startId)
      {
          System.out.println("Service is running!");
          isRunning = true;
          return START_STICKY;
      }
      @Override
      public IBinder onBind(Intent arg0) 
      {
          // TODO Auto-generated method stub
          return null;
      }
  
  }
  </code></pre>
  
  <p>Shouldn't myThread start executing, set LocalService.isRunning to true and allow the main thread to reach the print statement?  When I try this it always hangs on the while loop, what am I missing?  If I remove the while loop, myThread will execute but only after MyActivity's onCreate method has finished.  Can someone explain to me why they aren't running in parallel?</p>