Record a stopwatch app in Blackberry, how to make it more accurate

My application has a feature, for example, the BlackBerry Stopwatch application:
A label that displays the time updated every 100 milliseconds.

I used a separate thread for the timer, which TimerTask plans to update the label.

Everything works fine, but I noticed that the stopwatch in my application is a little slower than the built-in BlackBerry stopwatch - it loses 1 second per minute.
Sometimes the timer in my application stops for a while, about 300-500 milliseconds, for unknown reasons.

What can make a timer in my application slower than a BlackBerry stopwatch?
Any suggestions for creating a stopwatch that runs as smoothly as a BlackBerry stopwatch?

+3
source share
2 answers

To calculate the time, you should use System.currentTimeMillis (). The timer does not guarantee when it will run - the guarantee is that the specified time is the minimum delay before starting the launch, but there is no maximum, as you noticed. Therefore, use the Timer to schedule UI updates, but count the elapsed time using System.currentTimeMillis ().

+3
source

, . , 60 1 .

.

+2

Source: https://habr.com/ru/post/1772264/


All Articles