知道正常运行时间定时器复位或Android已经重新启动 [英] Know if uptime timer is reset or Android has been rebooted

查看:649
本文介绍了知道正常运行时间定时器复位或Android已经重新启动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用程序创建一个独立的时钟。时钟运行,如在活动中不同的线程,由我设定的基准时间开始。我更新使用uptimemillis之间的差异,当我设置了时钟,时钟,以及当前uptimemillis。但uptimetimer,可以由Android复位,并重新设置了Android的时候重启。

I have a independent clock created in my application. The clock runs as a different thread in the activity, starting from a base time set by me. I update the clock using the difference between the uptimemillis when I set the clock, and the current uptimemillis. But the uptimetimer, can be reset by Android, and is ever reset when Android reboot.

我只是想知道,如果运行时间定时器复位,要知道如果时钟仍然是可靠的。

I only want to know if the uptime timer is reset, to know if the clock is still reliable.

如何?

推荐答案

根据该文件,您可以使用的 SystemClock.elapsedRealtime()

According to the documentation you can use SystemClock.elapsedRealtime()

elapsedRealtime():
  返回自开机毫秒,包括在睡眠中度过的时间。

elapsedRealtime(): Returns milliseconds since boot, including time spent in sleep.

此值将仅在重新启动设备时复位。收听广播<一个href=\"http://developer.android.com/reference/android/Manifest.permission.html#RECEIVE_BOOT_COMPLETED\"相对=nofollow> boot_complete ,你会知道什么时候是。

This value will only be reset when the device is restarted. Listen to the broadcast boot_complete and you will know when that is.

与updateMillis()问题在文件中清楚地指出的:

The problem with the updateMillis() is clearly noted in the documentation:

uptimeMillis():
  返回毫秒启动以来,不包括在深度睡眠所花费的时间。注意:这个值可能会偶尔复位(前否则它将环绕)

uptimeMillis(): Returns milliseconds since boot, not counting time spent in deep sleep. Note: This value may get reset occasionally (before it would otherwise wrap around).

从我所理解的文档,通过使用elapsedRealtime用户无法操纵你的柜台。

From how I understand the documentation, by using elapsedRealtime your users cannot manipulate your counter.

这篇关于知道正常运行时间定时器复位或Android已经重新启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆