于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. schedule() 和 scheduleAtFixedRate() 区别

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

  2. schedule和scheduleAtFixedRate区别

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

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

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

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

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

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

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

  6. Android重绘ListView高度

    Android重绘ListView高度 经常会有这样需求,需要ListView默认将所有的条目显示出来,这就需要外层使用ScrollView,ScrollView里面放置一个重绘高度的ListView ...

  7. schedule与scheduleAtFixedRate比较

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

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

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

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

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

随机推荐

  1. android各种资源的详细解释

    1.字符数组      使用字符串数组资源<string-array>标签定义,在<string-array>包括一些标签<item>数组元素标记.   例如 &l ...

  2. ConcurrentHashMap中的2的n次方幂上舍入方法(转)

    最近看JDK中的concurrentHashMap类的源码,其中有那么一个函数: /** * Returns a power of two table size for the given desir ...

  3. 大约 Apple Metal API 一些想法

    看后 Metal 的开发文档后,除了官方所宣称的一些长处外(比方说更easy理解和使用的 API.更直接和精细的硬件控制,降低 GPU 使用过程中的 CPU 额外开销等等),从我有限的 GLES 开发 ...

  4. linux下安装cmake和mysql遇到的问题总结

    首先是在安装cmake的过程中遇到的问题: 1.開始使用yum命令安装时,不知道为什么一直不行,然后就准备wget 来先下载压缩包,再手动编译. 因为网络限制,wget不能下载外网的东西一直显示con ...

  5. devstack安装使用openstack常见问题与解决的方法

    声明: 本博客欢迎转发,但请保留原作者信息! 博客地址:http://blog.csdn.net/halcyonbaby 内容系本人学习.研究和总结.如有雷同,实属荣幸! 安装执行create-sta ...

  6. Xamarin C# Android for Visual Studio 平台安装

    原文:Xamarin C# Android for Visual Studio 平台安装 Xamarin是基于Mono的平台,目前主要有以下产品(更具体请见:http://xamarin.com/pr ...

  7. JS创建 trim() 方法,此方法在IE7、IE8中不存在 需要自定义

    function trim(str){ //创建空格对象 var space = new String(" "); /* str = trimLeft(str,space); st ...

  8. Linux从零到高手的进阶心得(转)

    从2006年毕业至今,从事IT行业已经接近8个年头. 一路走来有很多心路历程和技术心得都写在了51CTO的博客中,不少文字现在看来已显稚嫩,但是这正是我真实的成长之路.这八年,从最基础的网络管理员开 ...

  9. SQL Server :理解Page Free Space (PFS) 页

    原文:SQL Server :理解Page Free Space (PFS) 页 我们已经讨论了GAM与SGAM页,数据页(Data Page) ,现在我们来看下页面自由空间页(Page Free S ...

  10. ACM:回溯,八皇后问题,素数环

    (一)八皇后问题 (1)回溯 #include <iostream> #include <string> #define MAXN 100 using namespace st ...