how to wait for Android runOnUiThread to be finished?

后端 未结 7 1877
予麋鹿
予麋鹿 2020-12-29 00:58

I have a worker thread that creates a runnable object and calls runOnUiThread on it, because it deals with Views and controls. I\'d like to use the result of the work of the

相关标签:
7条回答
  • 2020-12-29 01:51

    Just scratching out the highlights

    synchronized( myRunnable ) {
       activity.runOnUiThread(myRunnable) ;
    
       myRunnable.wait() ; // unlocks myRunable while waiting
    }
    

    Meanwhile... in myRunnable...

    void run()
    {
       // do stuff
    
       synchronized(this)
       {
          this.notify();
       }
    }
    
    0 讨论(0)
提交回复
热议问题