首页 > 代码库 > 24 handle

24 handle

1 http://blog.csdn.net/dengxiayehu/article/details/6398648

       Handler mHandler = new Handler();

  1. Runnable workRunnable = new Runnable() {  
  2.         int counter = 0;  
  3.           
  4.         public void run() {  
  5.             if (counter++ < 1) {  
  6.                 Log.i(TAG, "workRunnable thread id = " +   
  7.                         Thread.currentThread().getId());  
  8.                 mHandler.postDelayed(workRunnable, DELAY_TIME);  
  9.             }  
  10.         }  

mHandler.postDelayed(workRunnable, DELAY_TIME); 

 mHandler.removeCallbacks(workRunnable);

handler将thread放入主线程,没有开辟新线程。