0

I have a set of instructions that needs to be executed repeatedly. The repeat delay is variable (the delay is taken from a file).

The repeat time must be very precise (milliseconds precision).

I have tried to use a Handler with postDelayed but the accuracy is lost in time. This happens because the repeat frequency is more than 10 times/second.

Any idea is more than welcomed!

Here is the Handler example:

new Runnable() {
        @Override
        public void run() {              
         mHandler.postDelayed(this, delay);               
         barometerResult.gotBarometer(barometerValueModelList.get(i).getBarometerValue());             
       }
    }.run();

1 Answers1

0

I don't think it's a good idea using Handler, it runs in the UI thread with many other things to do in the queue, so that's not guarantee your runnable code would be executed so precisely.

If your work in the Runnable is just some logic task not involved in update UI.Consider using a Timer to do that but be ware that it will run on a separated thread.

ytinrete
  • 46
  • 6