I am writing a simple timekeeping app for a specialized outdoor sport. The app performs a series of calculations every second, and displays information of interest to the user. Elapsed time is key to the accuracy of the calculated results. Ideally the calculation and results would be updated exactly every second. I have tried using a timer or a chronometer widget to control the update interval:
Is there a more accurate way to establish the interval? Is there a technique that will give me a nearly exact one second interval?
The code below is not complete - just an effort to show the type of time and chronometer I am using - they run fine, they are just not precise.
import java.util.Timer ;
import java.util.TimerTask;
...
myTimer = new Timer();
myTimer.schedule(new TimerTask() {
public void run() {
...
TimerMethod();
}
}, 0, 1000);
...
private void TimerMethod()
{
this.runOnUiThread(Timer_Tick);
}
...
private Runnable Timer_Tick = new Runnable() {
public void run() {
blah blah
}
///////////////////////////////
import android.widget.Chronometer;
...
final Chronometer myChronometer = (Chronometer)findViewById(R.id.chronometer);
final TextView keyBox = (TextView)findViewById(R.id.keyBox);
...
myChronometer.start();
...
myChronometer.setOnChronometerTickListener(
new Chronometer.OnChronometerTickListener(){
...
public void onChronometerTick(Chronometer myChronometer) {
blah blah
}