[英]How to implement the communication between Thread and AsyncTask
I am developing an application using Android SDK. 我正在使用Android SDK开发应用程序。 In this application I am facing a problem when an
Activity
starts a Thread
. 在此应用程序中,当
Activity
启动Thread
时,我面临一个问题。 The new Thread
starts an AsyncTask
, but the Thread
has to wait for completion of the AsyncTask
execution. 新
Thread
启动AsyncTask
,但Thread
必须等待AsyncTask
执行完成。
Is it possible to start AsyncTask
in a thread, and if so, how should it be implement? 是否可以在线
AsyncTask
,如果可以,应如何实现? Please can anyone share your experience with me about this kind of tasks. 请任何人与我分享您对此类任务的经验。
Thanks in advance 提前致谢
just say thread to sleep for some times and then check a variable again like this in below code someValue was setted in asynctask postExecute method 只是说线程要休眠一段时间,然后再在下面的代码中像这样检查一个变量,在asynctask postExecute方法中设置了someValue
new Thread(new Runnable(){
@Override
public void run(){
while(!someValue) {
try {
Thread.sleep(200);
} catch {
Log.i("LOG", "ERROR");
}
}
Log.i("LOG", "Async Task Finished");
}
}).start();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.