2012-03-23 74 views

回答

0

實施例1:

Handler threadHandler=new Handler(); 
     threadHandler.postDelayed(new Runnable() { 
      public void run() { 
       // do your task here ..it will execute after 100 ms in separate thread 
      } 
     }, 100L); 

實施例2:

 final Handler mHandler = new Handler(Looper.getMainLooper()); 
         new Thread(){ 
          /* (non-Javadoc) 
          * @see java.lang.Thread#run() 
          */ 
          @Override 
          public void run() { 
    // do your task here.. it will execute in seperate thread 
// you can post your result from here using mHandler.post Method. 
         }  
         }.start(); 

有很多教程可用互聯網上。你可以很容易地找到它。

看到這一點:

http://mindtherobot.com/blog/159/android-guts-intro-to-loopers-and-handlers/

0

可運行代表處理程序的代碼作爲對象,後一方法可運行bloack,requries可運行的對象作爲輸入,處理程序執行哪個。