本文介绍了Android的阻断::主线程的工作线程在主线程执行其他任务前完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我执行在UI线程任务的一些创造一个工作线程,做网络的东西我。不过,我有重要的事情需要一旦工作线程完成执行。有谁请建议我一个解决方案吗?
I am executing some task in the UI thread and created a worker thread that does the networking stuff for me. However, I have something important that needs to be executed once the worker thread finishes. Could anybody please suggest me a solution?
{
Main thread...
worker thread created..and executed..
//I need to wait here for the worker thread to finish//
some useful task to be done
}
在此先感谢!
推荐答案
您需要的工人结束后做UI线程上的东西呢?使用 runOnUiThread
在你的工人年底或使用的AsyncTask
与 onPostExecute()
。阻塞UI线程,而工人正在运行没有任何意义。
You need to do things on the UI thread after worker has finished? Use runOnUiThread
at the end of your worker or use AsyncTask
with onPostExecute()
. Blocking the UI thread while worker is running doesn't make any sense.
这篇关于Android的阻断::主线程的工作线程在主线程执行其他任务前完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!