Android java 关于 Timer schedule 执行定时任务

来源:互联网 发布:俊平护肤品怎么样知乎 编辑:程序博客网 时间:2024/05/22 10:55

只执行一次的方法

Timer.schedule(TimerTask task, long delay)方法在程序中只执行一次(long delay 为距离启动任务的时间差) 

注释:Schedules the specified task for execution after the specified delay。大意是在延时delay毫秒后执行task。

 Timer.schedule(TimerTask task, Date time) 方法在程序中只执行一次(Date time 为设定的启动时间)

重复执行方法

Timer.schedule(TimerTask task, long delay, long period)是重复的执行 

注释:Schedules the specified task for repeated fixed-delay execution, beginning after the specified delay。大意是在延时delay毫秒后重复的执行task,周期是period毫秒

 Timer.schedule(TimerTask task, Date time, long period) 是重复的执行 (Date time 为启动时间)

0 0
原创粉丝点击