title: Android: New Thread Runnable Executes in Main Thread
body: <p>I'm trying to create a new thread in the onCreate() of an activity, but instead of creating a new thread and executing the runnable's code in it, the runnable code is executing in the main thread of my program.  A new thread never seems to be created.</p>
  
  <p>The onCreate() code:</p>
  
  <pre><code>@Override
  protected void onCreate(Bundle savedInstanceState){
      super.onCreate(savedInstanceState);
      setContentView(R.layout.monster_layout);
      runningMonsterViewActivity = this;
      Thread.currentThread().setName("Main Thread");
      Log.v(TAG, "onCreate() has run");
      Thread genThread = new Thread(new TestRunnable());
      genThread.run();
  }
  </code></pre>
  
  <p>The runnable code:  </p>
  
  <pre><code>import android.os.Handler;
  import android.util.Log;
  
  public class TestRunnable implements Runnable{
  String TAG = "TestRunnable";
  
      public TestRunnable()
      {
      //  mainThreadHandler = h;
      }
      @Override
      public void run() {
          for(int i=0; i &lt; 1000; i++){
              Log.v(TAG, new Integer(i).toString());
              try {
                  Thread.sleep(1000);
              } catch (InterruptedException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
              }
          }
  
      }
  }
  </code></pre>
  
  <p>The stack trace I got when I paused the code when it was executing:</p>
  
  <pre><code>DalvikVM[localhost:8621] (Suspended)    
      Thread [&lt;1&gt; Main Thread] (Suspended)    
          VMThread.sleep(long, int) line: not available [native method]   
          Thread.sleep(long, int) line: 1306  
          Thread.sleep(long) line: 1286   
          TestRunnable.run() line: 18 
          Thread.run() line: 1096 
          MonsterViewActivity.onCreate(Bundle) line: 49   
          Instrumentation.callActivityOnCreate(Activity, Bundle) line: 1047   
          ActivityThread.performLaunchActivity(ActivityThread$ActivityRecord, Intent) line: 2627  
          ActivityThread.handleLaunchActivity(ActivityThread$ActivityRecord, Intent) line: 2679   
          ActivityThread.access$2300(ActivityThread, ActivityThread$ActivityRecord, Intent) line: 125 
          ActivityThread$H.handleMessage(Message) line: 2033  
          ActivityThread$H(Handler).dispatchMessage(Message) line: 99 
          Looper.loop() line: 123 
          ActivityThread.main(String[]) line: 4627    
          Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method]  
          Method.invoke(Object, Object...) line: 521  
          ZygoteInit$MethodAndArgsCaller.run() line: 868  
          ZygoteInit.main(String[]) line: 626 
          NativeStart.main(String[]) line: not available [native method]  
      Thread [&lt;6&gt; Binder Thread #2] (Suspended)   
      Thread [&lt;5&gt; Binder Thread #1] (Suspended)   
      Daemon System Thread [&lt;3&gt; Signal Catcher] (Suspended)   
      Daemon System Thread [&lt;2&gt; HeapWorker] (Suspended)   
  </code></pre>