如何等待Android的runOnUiThread要完蛋? [英] how to wait for Android runOnUiThread to be finished?

查看:495
本文介绍了如何等待Android的runOnUiThread要完蛋?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个创建一个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();
   }
}

这篇关于如何等待Android的runOnUiThread要完蛋?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆