如何等待Android的runOnUiThread要完蛋?Android、runOnUiThread

由网友(泪染裳ぅ)分享简介:我有一个创建一个Runnable对象,并调用它runOnUiThread,因为它涉及查看和控制辅助线程。我想用Runnable对象的工作结果的时候了。我如何等待它完成?它不打扰我,如果它的阻止。 I have a worker thread that creates a runnable object and cal...

我有一个创建一个Runnable对象,并调用它runOnUiThread,因为它涉及查看和控制辅助线程。我想用Runnable对象的工作结果的时候了。我如何等待它完成?它不打扰我,如果它的阻止。

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 runnable object right away. How do I wait for it to finish? It doesn't bother me if it's blocking.

推荐答案

刚挠出亮点

synchronized( myRunnable ) {
   activity.runOnUiThread(myRunnable) ;

   myRunnable.wait() ; // unlocks myRunable while waiting
}

与此同时......在myRunnable ...

Meanwhile... in myRunnable...

void run()
{
   // do stuff

   synchronized(this)
   {
      this.notify();
   }
}
阅读全文

相关推荐

最新文章