在android中调度定时任务有两种方法

1.schedule

2.scheduleAtFixedRate

这两种方法的差别在于
首次调用时间(Date when)这个參数

<span style="font-family:SimHei;font-size:14px;">        // TimerTask
task = new TimerTask() {
@Override
public void run() {
// 输出当前毫秒为单位的时间
Log.i("Test", ">>>" + System.currentTimeMillis());
}
}; // 获取毫秒为单位的当前时间
long crt = System.currentTimeMillis(); timer = new Timer();
// 调度,以当前毫秒时间减10秒
// timer.schedule(task, new Date(crt - 10 * 1000), 2000);
timer.scheduleAtFixedRate(task, new Date(crt - 10 * 1000), 2000);</span>

schedule调度不会去计算首次调用时间  它会马上调用一次 在之后每2秒调用一次

scheduleAtFixedRate 调度则会计算首次调用时间,因为我们首次调用时间设置为当前时间减10秒。那么在运行时会先计算出这10秒内应task应运行的次数,再去按设定频率去运行。

Android 定时任务高度【schedule】与【scheduleAtFixedRate】差别的更多相关文章

  1. Timer类的schedule和scheduleAtFixedRate 简单应用

    Timer类可以用作定时任务,主要的方法有schedule和scheduleAtFixedRate. schedule(TimerTask task, Date time) 安排在指定的时间执行指定的 ...

  2. schedule() 和 scheduleAtFixedRate() 区别

    1.  schedule() ,2个参数方法:在执行任务时,如果指定的计划执行时间scheduledExecutionTime <= systemCurrentTime,则task会被立即执行. ...

  3. schedule和scheduleAtFixedRate区别

    需求: 由于系统长期运作,各设备之间产生很多信息,一段时间后需要清除数据 考虑方案: 用schedule还是scheduleAtFixedRate,在此比较分析了下这两个的区别 schedule和sc ...

  4. schedule() 和 scheduleAtFixedRate() 的区别--转载

    1.  schedule() ,2个参数方法:在执行任务时,如果指定的计划执行时间scheduledExecutionTime <= systemCurrentTime,则task会被立即执行. ...

  5. 简单理解java中timer的schedule和scheduleAtFixedRate方法的区别

    timer的schedule和scheduleAtFixedRate方法一般情况下是没什么区别的,只在某个情况出现时会有区别--当前任务没有来得及完成下次任务又交到手上. 我们来举个例子: 暑假到了老 ...

  6. schedule与scheduleAtFixedRate比较

    schedule与scheduleAtFixedRate: 不延时: schedule(TimerTask, Date runDate, long period)方法任务不延时----Date类型 i ...

  7. Timer的schedule和scheduleAtFixedRate方法的区别解析(转)

    在java中,Timer类主要用于定时性.周期性任务 的触发,这个类中有两个方法比较难理解,那就是schedule和scheduleAtFixedRate方法,在这里就用实例分析一下 (1)sched ...

  8. Timer的schedule和scheduleAtFixedRate方法的区别解析

    在java中,Timer类主要用于定时性.周期性任务 的触发,这个类中有两个方法比较难理解,那就是schedule和scheduleAtFixedRate方法,在这里就用实例分析一下 (1)sched ...

  9. android 定时任务

    使用timertask进行定时任务 首先创建TimerTask: class SynchroTimerTask extends TimerTask { @Override public void ru ...

随机推荐

  1. Linux使用wake_up_interruptible()唤醒注册到等待队列上的进程

    http://blog.sina.com.cn/s/blog_4770ef020101h48l.html     功能:唤醒注册到等待队列上的进程 原型:     #include     void ...

  2. JNI编程(二) —— 让C++和Java相互调用(2)

    3.getRamdomOrder() 这个方法会从backend得到一个随机的Order对象(抱歉这里“Random”拼错了),然后再调用java中相应的通知方法来通知foreground.getRa ...

  3. access to modified closure 闭包的问题

    ; i < listBoxDevices.Items.Count; i++) { var tempDeviceId = listBoxDevices.Items[i].ToString(); i ...

  4. 登陆与注册以及Session

    Session  保存状态是在 登陆窗口  检查用户密码的动作上执行 .Models namespace 注册与登陆以及Session.Models { public class UserBF { p ...

  5. bzoj2527

    首先环可以变成链来处理,对于l>r的情况就是修改区间[1,r],[l,mx]然后不难想到整体二分,二分答案k,然后算1~k场流星雨对国家的贡献然后判定将国家划分变成子问题解决,没什么难的终于不是 ...

  6. [POJ 2019] Cornfields

    Cornfields Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 5516   Accepted: 2714 Descri ...

  7. java类转化为json对象

    方式一:使用jar包,直接转化成json格式,再使用outwrite写到jsp中 先说说要使用到的包commons-beanutils.jar.commons-collections.jar.comm ...

  8. wpa_supplicant使用笔记

    还在搞8634,看不到头了..唉.wireless_tools的缺点是不支持WPA认证,所以有必要把wpa_supplicant也移植过来.无线 网卡是基于zydas芯片的,正好可以在网上搜到wpa_ ...

  9. 关于HTTP返回码301、302区别与SEO

    301(永久移动)请求的网页已永久移动到新位置.服务器返回此响应时,会自动将请求者转到新位置.您应使用此代码告诉搜索引擎Spider某个网页或网站已永久移动到新位置.建议在URL规范化的时候采用301 ...

  10. 用excel打造报表查询系统

    网络数据库以及ERP在中小型企业中日益风行,虽然ERP功能强大,但有的ERP报表系统中规范的报表较少,主要提供二次开发接口或通过如CRYSTALREPORT等其他报表工具进行管理,其实我们可以使用Ex ...