How to Reduce Thread.sleep() Latency in Android

后端 未结 1 710
隐瞒了意图╮
隐瞒了意图╮ 2021-01-19 12:51

I am generating timing events in a loop in a (non-UI) thread in an Android application, and I need those events to occur at precise intervals in time, (precise here means no

相关标签:
1条回答
  • 2021-01-19 13:23

    I'm using delayed messages with Handler for similar purpose. It can be little overkill. In you case I would take a look to Timer class.

    mTimer = new Timer();
    mTimer.scheduleAtFixedRate(new TimerTask() {
        @Override
        public void run() {
            Log.v("TEST", " tick");
        }
    }, 0, 250);
    

    This gives me latency +-2 millisecs at emulator.

    0 讨论(0)
提交回复
热议问题