我在我的应用程序中处理一个线程,我遇到了线程等待功能的问题。我使用创建并显示我的 UI runOnUIThread()
,我的主线程正在等待我的 UI 线程完成,线程完成后我在主线程中做了一些处理,这里的问题是主进程始终处于等待状态,即使我的线程完成它;我正在notify()
为此使用等待和函数
public String LSVerification() {
String t = null;
t="Sample string";
synchronized(this)
{
AndroidHTMLActivity.this.runOnUiThread(ShowDialog) ;//here i call my thread
try {
this.wait();//here i waiting for my thread to finish it's job
//here i do some process after my thread finish it's job
//the problem is here main process always in wait state
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return t;
}
private Runnable ShowDialog = new Runnable() {
public void run() {
String t = null;
synchronized(ShowDialog)
{
Recognition recg=new Recognition(Activity.this);
recg.show();
this.notify();
}
}
};