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_CHANGED
andACTION_TIMEZONE_CHANGED
Intent
broadcasts 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
Handler
class 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
AlarmManager
can 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 anIntent
broadcast 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官方简介 上面的话简单的总结来说 ...
随机推荐
- C++程序员的阅读清单
link:http://www.who1753.com/must-read-c-book-list/ 多读一些优秀的书籍,对于开发者稳固编程基础.提高编程技能有很大帮助.但是,大多时候,初学者不知道应 ...
- HNOI2015 Day 2题解
昨天做了HNOI day 2,感觉好像还是可做的,想当年什么splay还是高级算法,现在点剖什么就老考了简直丧病,虽然第二题还没写那就先当下嘴巴选手吧= = T1:[HNOI2015]落忆枫音 描述: ...
- 令人费解的java泛型
对于我们java中的泛型,可能很多人知道怎么使用并且使用的还不错,但是我认为想要恰到好处的使用泛型,还是需要深入的了解一下它的各种概念和内部原理.本文将尽可能的囊括java泛型中的重要的概念 ...
- linux c++ 加载动态库常用的三种方法
链接库时的搜索路径顺序:LD_LIBRARY_PATH --> /etc/ld.so.conf --> /lib,/usr/lib 方法1. vi .bash_profile 设置环 ...
- ShiWangMeSDK Android版接口文档 0.2.0 版
# ShiWangMeSDK Android版接口文档 0.2.0 版 android 总共有 14 个接口,分别涉及到初始化和对界面的一些细节的控制.下面详细介绍接口,如果没有特殊说明,接口都在 S ...
- oracle数据库命令-持续更新
一.系统命令 登录 dba用户命令 sqlplus / as sysdba 2. 用户命令 删除用户 DROP USER **** CASCADE; DROP SCHEMA **** CASCADE; ...
- npm学习总结
1.npm run [scripts name]的作用及意义: npm 局部安装的工具包不能像全局安装那样直接执行命令行,但可写成命令行执行语句,通过npm run来运行,该命令可将node_modu ...
- Eclipse:The selection cannot be launched,and there are no recent launches
刚刚装上eclipse,于是就想写个Java程序来试试.结果写好之后不管是点击 run 还是 debug 结果都会弹出一个窗口,内容为: The selection cannot be launc ...
- OpenFlow硬件交换机制作及刷机教程
1.目的 将普通路由器升级成为一台支持OpenFlow的交换机. 具体哪些路由器可以刷OpenFlow可以参考:OpenWRT:http://wiki.openwrt.org/toh/start#su ...
- css中设置div垂直水平居中的方法
设置要水平垂直居中的div的position为absolute,left:50%;margin-left为负的这个元素宽度的一半,同理,top:50%;margin-top为负的这个元素的高度的一半. ...