When the worker thread works, UI becomes choppy

前端 未结 3 1708
野的像风
野的像风 2020-12-31 12:28

I have a handwriting recognition app - the user draws with their finger, the app recognizes characters. The recognition engine runs in a worker thread that has the the minim

3条回答
  •  醉酒成梦
    2020-12-31 13:27

    Try to add Thread.sleep(1) in main cycle in character recognition method

    @Override
    public void run() {
      while (!recognited) {
    
        //do some script
    
        try {
          Thread.sleep(1);
        } catch (InterruptedException e) {
          e.printStackTrace();
        }
      }
    }
    

    this sleep lets virtual machine to resume other thread a bit early and often

提交回复
热议问题