android中延遲執行某個任務

下面是三種方法:

1、線程android

 new Thread(new Runnable(){    post

     public void run(){    spa

        Thread.sleep(XXXX);    線程

         handler.sendMessage(); //----告訴主線程執行任務    方法

     }    im

 }).start    handler

2、延時器time

 TimerTask task = new TimerTask(){    消息

     public void run(){    new

     //execute the task     

     }    

 Timer timer = new Timer();  

   timer.schedule(task, delay);  

3、android消息處理

new Handler().postDelayed(new Runnable(){    

    public void run() {    

    //execute the task    

    }    

 }, delay);   

推薦使用第三種

相關文章
相關標籤/搜索