既然handler和activity是在同一个线程,运行Thread中的run()方法中的Thread.sleep(5000),为什么Thread中的System.out.println没有先执行,而是先执行Activity中的System.out.println(); package cc.handler2;import android.os.Bundle;
import android.os.Handler;
import android.app.Activity;
import android.util.Log;
import android.view.Menu;public class MainActivity extends Activity { private Handler handler = new Handler();
@Override
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);
handler.post(thread);
// thread.start();
setContentView(R.layout.activity_main);
System.out.println("thread333--"+Thread.currentThread().getId());
System.out.println("thread333--"+Thread.currentThread().getName());

} Thread thread = new Thread()
{

public void run() 
{
System.out.println("thread"+Thread.currentThread().getId());
System.out.println("thread"+Thread.currentThread().getName());
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("thread"+Thread.currentThread().getId());
System.out.println("thread"+Thread.currentThread().getName());


};
};
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}}