SystemClock官方简介
SystemClock
extends Object
| java.lang.Object | |
| ↳ | android.os.SystemClock |
Class Overview
Core timekeeping facilities.
Three different clocks are available, and they should not be confused:
System.currentTimeMillis()is the standard "wall" clock (time and date) expressing milliseconds since the epoch. The wall clock can be set by the user or the phone network (seesetCurrentTimeMillis(long)), so the time may jump backwards or forwards unpredictably. This clock should only be used when correspondence with real-world dates and times is important, such as in a calendar or alarm clock application. Interval or elapsed time measurements should use a different clock. If you are using System.currentTimeMillis(), consider listening to theACTION_TIME_TICK,ACTION_TIME_CHANGEDandACTION_TIMEZONE_CHANGEDIntentbroadcasts to find out when the time changes.uptimeMillis()is counted in milliseconds since the system was booted. This clock stops when the system enters deep sleep (CPU off, display dark, device waiting for external input), but is not affected by clock scaling, idle, or other power saving mechanisms. This is the basis for most interval timing such asThread.sleep(millls),Object.wait(millis), andSystem.nanoTime(). This clock is guaranteed to be monotonic, and is suitable for interval timing when the interval does not span device sleep. Most methods that accept a timestamp value currently expect theuptimeMillis()clock.elapsedRealtime()andelapsedRealtimeNanos()return the time since the system was booted, and include deep sleep. This clock is guaranteed to be monotonic, and continues to tick even when the CPU is in power saving modes, so is the recommend basis for general purpose interval timing.
There are several mechanisms for controlling the timing of events:
Standard functions like
Thread.sleep(millis)andObject.wait(millis)are always available. These functions use theuptimeMillis()clock; if the device enters sleep, the remainder of the time will be postponed until the device wakes up. These synchronous functions may be interrupted withThread.interrupt(), and you must handleInterruptedException.SystemClock.sleep(millis)is a utility function very similar toThread.sleep(millis), but it ignoresInterruptedException. Use this function for delays if you do not useThread.interrupt(), as it will preserve the interrupted state of the thread.The
Handlerclass can schedule asynchronous callbacks at an absolute or relative time. Handler objects also use theuptimeMillis()clock, and require anevent loop(normally present in any GUI application).The
AlarmManagercan trigger one-time or recurring events which occur even when the device is in deep sleep or your application is not running. Events may be scheduled with your choice ofcurrentTimeMillis()(RTC) orelapsedRealtime()(ELAPSED_REALTIME), and cause anIntentbroadcast when they occur.
Summary
| Public Methods | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| static long | currentThreadTimeMillis()
Returns milliseconds running in the current thread.
|
||||||||||
| static long | elapsedRealtime()
Returns milliseconds since boot, including time spent in sleep.
|
||||||||||
| static long | elapsedRealtimeNanos()
Returns nanoseconds since boot, including time spent in sleep.
|
||||||||||
| static boolean | setCurrentTimeMillis(long millis)
Sets the current wall time, in milliseconds.
|
||||||||||
| static void | sleep(long ms)
Waits a given number of milliseconds (of uptimeMillis) before returning.
|
||||||||||
| static long | uptimeMillis()
Returns milliseconds since boot, not counting time spent in deep sleep.
|
||||||||||
| [Expand]
Inherited Methods
|
|||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
From class java.lang.Object
|
|||||||||||
Public Methods
public static long currentThreadTimeMillis ()
Returns milliseconds running in the current thread.
Returns
- elapsed milliseconds in the thread
public static long elapsedRealtime ()
Returns milliseconds since boot, including time spent in sleep.
Returns
- elapsed milliseconds since boot.
public static long elapsedRealtimeNanos ()
Returns nanoseconds since boot, including time spent in sleep.
Returns
- elapsed nanoseconds since boot.
public static boolean setCurrentTimeMillis (long millis)
Sets the current wall time, in milliseconds. Requires the calling process to have appropriate permissions.
Returns
- if the clock was successfully set to the specified time.
public static void sleep (long ms)
Waits a given number of milliseconds (of uptimeMillis) before returning. Similar to sleep(long), but does not throw InterruptedException; interrupt() events are deferred until the next interruptible operation. Does not return until at least the specified number of milliseconds has elapsed.
Parameters
| ms | to sleep before returning, in milliseconds of uptime. |
|---|
public static long uptimeMillis ()
Returns milliseconds since boot, not counting time spent in deep sleep.
Returns
- milliseconds of non-sleep uptime since boot.
SystemClock官方简介的更多相关文章
- 老李推荐:第5章1节《MonkeyRunner源码剖析》Monkey原理分析-启动运行: 官方简介
老李推荐:第5章1节<MonkeyRunner源码剖析>Monkey原理分析-启动运行: 官方简介 在MonkeyRunner的框架中,Monkey是作为一个服务来接受来自Monkey ...
- 第5章1节《MonkeyRunner源码剖析》Monkey原理分析-启动运行: 官方简介(原创)
天地会珠海分舵注:本来这一系列是准备出一本书的,详情请见早前博文“寻求合作伙伴编写<深入理解 MonkeyRunner>书籍“.但因为诸多原因,没有如愿.所以这里把草稿分享出来,所以错误在 ...
- Android4.3引入的UiAutomation新框架官方简介
译者序:Google在Android 4.3发布时提供了一套新的UiAutomation框架来支持用户界面自动化测试,该框架通过运用已有的Accessibility APIs来模拟用户跟设备用户界面的 ...
- 阿里 RocketMQ 安装与简介
一.简介 官方简介: l RocketMQ是一款分布式.队列模型的消息中间件,具有以下特点: l 能够保证严格的消息顺序 l 提供丰富的消息拉取模式 l 高效的订阅者水平扩展能力 l 实时的 ...
- Hadoop MapReduceV2(Yarn) 框架简介[转]
对于业界的大数据存储及分布式处理系统来说,Hadoop 是耳熟能详的卓越开源分布式文件存储及处理框架,对于 Hadoop 框架的介绍在此不再累述,读者可参考 Hadoop 官方简介.使用和学习过老 H ...
- Hadoop MapReduceV2(Yarn) 框架简介
http://www.ibm.com/developerworks/cn/opensource/os-cn-hadoop-yarn/ 对于业界的大数据存储及分布式处理系统来说,Hadoop 是耳熟能详 ...
- Linux 内存管理之highmem简介
一.Linux内核地址空间 一般来说Linux 内核按照 3:1 的比率来划分虚拟内存(X86等):3 GB 的虚拟内存用于用户空间,1GB 的内存用于内核空间.当然有些体系结构如MIPS使用2:2 ...
- Android Studio重构之路,我们重新来了解一下Google官方的Android开发工具
Android Studio重构之路,我们重新来了解一下Google官方的Android开发工具 记得我的第一篇博客就是写Android Studio,但是现在看来还是有些粗糙了,所有重构了一下思路, ...
- Python【初识篇】简介
python是什么? 为什么学python? python在权威语言排序网站上的热度 python历史排名 python应用领域 哪些公司在用python python官方简介 上面的话简单的总结来说 ...
随机推荐
- 剖析Asp.Net Web API中HttpController的激活
在Asp.Net Web API中,请求的目标是定义在某个HttpController中的某个Action方法.当请求经过Asp.Net Web API消息处理管道到达管道"龙尾" ...
- NodeJs之crypto
NodeJs版本:4.4.4 crypto nodejs提供了内置加密模块crypto. 加密模块提供了 HTTP 或 HTTPS 连接过程中封装安全凭证的方法. 它也提供了 OpenSSL 的哈希, ...
- 在Windows Server2016里通过Hyper-V安装Liunx Container
Windows Server2016正式发布已经有一段时间了.无可厚非,原生Docker的支持是这个版本一个非常大的亮点. Windows Container 的安装在网上有很多教程,我这里不过多的描 ...
- iOS 用Swipe手势和动画实现循环播放图片
主要想法 添加3个ImageView展示图片,实现图片的无限循环. 使用Swipe手势识别用户向右或向左滑动图片. 使用CATransition给ImageView.layer添加动画,展示图片更换的 ...
- 用DotRas来连接VPN网络
最近要用程序来不断的连接VPN(为什么要这样就不讨论了),开始用的是如下代码: public static bool ADSL() { bool flag = true; do { Console.W ...
- chrome浏览器美化插件:让你的浏览器页面冒水泡, 游小鱼儿
下载插件和效果图 这是一个让你的浏览器冒泡泡的插件, 浏览网页的时候仿佛置身于海底世界: 插件下载地址:http://files.cnblogs.com/files/diligenceday/chro ...
- Linux实战教学笔记21:Rsync数据同步工具
第二十一节 Rsync数据同步工具 标签(空格分隔): Linux实战教学笔记-陈思齐 ---本教学笔记是本人学习和工作生涯中的摘记整理而成,此为初稿(尚有诸多不完善之处),为原创作品,允许转载,转载 ...
- SpringBoot之旅 -- SpringBoot 项目健康检查与监控
前言 You build it,You run it, 当我们编写的项目上线后,为了能第一时间知晓该项目是否出现问题,常常对项目进行健康检查及一些指标进行监控. Spring Boot-Actuato ...
- 2017-3-17 SQL server 数据库 视图,事务,备份还原,分离附加
1.视图:只能查看,不能增删改不能有重复列 create view 名字as查询语句 2.事务:保证流程的完整执行 begin tran --开始事务监控 被监控的代码 ... ...if @@ERR ...
- 队列工厂之RedisMQ
本次和大家分享的是RedisMQ队列的用法,前两篇文章队列工厂之(MSMQ)和队列工厂之RabbitMQ分别简单介绍对应队列环境的搭建和常用方法的使用,加上本篇分享的RedisMQ那么就完成了咋们队列 ...
From class