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官方简介 上面的话简单的总结来说 ...
随机推荐
- Cloud9vue&vux上传github小步骤
成功后创建出以下文件,再输入: git init 再输入:$ git remote add origin https://github.com/github用户名/vux1 然后:git add. 按 ...
- 做了个新的UWP类库 Sharp2D
C#开发UWP的时候如果要实现高斯模糊效果的话,最好的选择似乎是微软的Win2D 但是Win2D太过庞大了,仅仅是庞大其实也没啥问题,毕竟net core就很庞大,但Win2d是一个Winmd组件 w ...
- C#中判断字符串相等的方法
可以使用如下方式: 1. String.Compare(str1, str2) == 0 或者 str1.CompareTo(str2) == 0 2. str1.Equals(str2) 或者 ...
- thinkphp join加别名
//此段代码在某个Model里面$tbpre = $this->tableprefix;$Aaa = M('aaa');$Aaa->table(array("{$tbpre}aa ...
- jquery事件与绑定事件
1.首先,我们来看一下经常使用的添加事件的方式: <input type="button" id="btn" value="click me!& ...
- 常见的html面试题
1.doctype作用?标准模式和兼容模式各有什么区别? (1).<doctype>声明位于文档第一行,在<html>标签之前.用于告知浏览器的解析器以什么样的标准解析该文档. ...
- 1640: [Usaco2007 Nov]Best Cow Line 队列变换
1640: [Usaco2007 Nov]Best Cow Line 队列变换 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 543 Solved: 2 ...
- [lua] 你所不知道的lua nil值在可变参数函数中怎么处理!
在lua中, 问题1:如果你在可变参数...中传入若干个参数,其中有的参数要带nil,这时怎么解决呢?(比如local function _test(...) end _test(1, nil, ...
- 轻松理解JavaScript之AJAX
摘要 AJAX技术是网页构建的必备技能之一,本文希望能帮助大家轻松的学习这项技术 一.什么是ajax? ajax(异步javascript xml) 能够刷新局部网页数据而不是重新加载整个网页. 二. ...
- zTree的拖拽排序
ztree本身是可以支持拖拽的,但是却没有找到明确的支持拖拽的排序,也就是说,在拖拽过程中,需要自定义维护拖拽后的顺序并保存至后台. 在这样一个比较常规的需求情况下,网上也有朋友给出了一些解决方案,比 ...
From class