Android的 - CountDownTimer间隔不恒定 [英] Android - CountDownTimer interval is not constant

查看:507
本文介绍了Android的 - CountDownTimer间隔不恒定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在与制作countdowntimer

When making the countdowntimer with

new CountDownTimer(interval,1000)
{
.
.
}

我希望得到的蜱在1秒内,但显然区间是相当随机的,正因为如此,有时定时器跳过1秒。

I expect to get 1 second period in between ticks, but apparently the interval is quite random and because of that, sometimes the timer skipped 1 second.

当我直接显示米利斯实验中,间隔范围为900-1150,并经常跳过,因为那一秒。

When I experiment by displaying the millis directly, the interval ranges from 900-1150, and often skips one second because of that.

我该如何解决这个问题?

How can I fix this?

推荐答案

您可能不希望如果毫秒重要的是使用这种方法。你或许应该检查系统时间,看看1000米利斯过去了,跟踪,当你开始计数。然后,在长期内(如1000米利斯),你可以纠正沿途计数器的误差。

You probably don't want to use this approach if milliseconds are important. You should probably check the system time to see if 1000 millis have elapsed and keep track of when you started counting. Then over long periods (like 1,000 millis) you can correct for the inaccuracy of the counter along the way.

下面是上好的帖子:如何计算经过时间

使用该检查每100毫秒时间或500米利斯与定时器经过时间。给用户时,100毫秒时间可能不会被察觉。但在很长计数周期就会积少成多。这是一个更好的方法。

Use that to check elapsed time every 100 millis or 500 millis with your timer. To a user, 100 millis probably won't be noticed. But over long counting periods it will add up. This is a better approach.

这篇关于Android的 - CountDownTimer间隔不恒定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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