这个程序证明了用handler.post(r);不能产生多线程,而用Thread t = new Thread(r);t.start();才是真正的多线程
Code package tk.handertest2; import android.os.Bundle; import android.os.Handler; import android.app.Activity; import android.view.Menu; public class MainActivity extends Activity { private Handler handler = new Handler(); @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // handler.post(r); Thread t = new Thread(r); t.start(); System.out.println("Activity--->"+Thread.currentThread().getId()); System.out.println("Activityname--->"+Thread.currentThread().getName()); } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.activity_main, menu); return true; } Runnable r=new Runnable() { @Override public void run() { System.out.println("handler--->"+Thread.currentThread().getId()); System.out.println("handlername--->"+Thread.currentThread().getName()); try { Thread.sleep(10000); } catch (InterruptedException e) { // TODO: handle exception e.printStackTrace(); } } }; }