作者:凌子的夏天_952 | 来源:互联网 | 2023-09-23 18:08
Ihavebeenbuildingasmalldarkroomtimerapplication,asIlearnAndroidandjava.Endedupusing
I have been building a small darkroom timer application, as I learn Android and java.
Ended up using CountDownTimer, as it does most of the work for me. :{)
However, I ran into what looks like an error in the class.
当我学习Android和java时,我一直在构建一个小的暗室计时器应用程序。使用CountDownTimer结束,因为它为我完成了大部分工作。 :{}但是,我遇到了类中的错误。
My initial structure used the onTick() callback to decrement my time counter, and update the time-remaining display. If I set it up for example:
我的初始结构使用onTick()回调来减少我的时间计数器,并更新剩余时间显示。如果我将其设置为例如:
new CountDownTimer(60000, 100) {
public void onTick(long millisUntilFinished) {
mDisplayTime.setText(String.valueOf(millisUntilFinished)/1000);
timeTenths -= 1;
updateDisplay();
}
public void onFinish() {
// mDisplayTime.setText("Done!");
}
}.start();
The total timeout (60 seconds) is spot on, within half a second by my stopwatch.
However, the displayed count stops with 3.0 seconds on the clock.
Experimenting with it, I found a consistent 5% "shortage" in onTick() events.
I could change the second parameter to 950 milliseconds, but that's an ugly kludge...
我的秒表在半秒内完成超时(60秒)。但是,显示的计数在时钟上停止了3.0秒。通过试验,我在onTick()事件中发现了一致的5%“短缺”。我可以将第二个参数更改为950毫秒,但这是一个丑陋的kludge ......
In the end, I changed the onTick() to display actual millisUntilFinished, which is fine, and eliminates my counter as well.
最后,我更改了onTick()以显示实际的millisUntilFinished,这很好,并且也消除了我的计数器。
Is this a known problem with CountDownTimer()?
这是CountDownTimer()的已知问题吗?
Dave
1 个解决方案