您的位置:首页 > 移动开发 > Android开发

android中延时操作三种方式

2016-03-18 16:35 375 查看
下面是三种方法:

一、线程

[html] view
plaincopy

 new Thread(new Runnable(){    

     public void run(){    

         Thread.sleep(XXXX);    

         handler.sendMessage();----告诉主线程执行任务    

     }    

 }).start    

二、延时器

[html] view
plaincopy

 TimerTask task = new TimerTask(){    

     public void run(){    

     //execute the task     

     }    

  
};    

   Timer timer = new Timer();  

   timer.schedule(task, delay);  

三、android消息处理

[html] view
plaincopy

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

    public void run() {    

    //execute the task    

    }    

 }, delay);   

推荐使用第三种
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息