I need to know how to wait for event to be triggered to set a Boolean. I got 2 classes simple classes: MainClass and Wait class:
MainClass()
{
WebView wv; //It's already initialized from the xml and linked in the original code
Wait waiting = new Wait();
if(waiting(wv,URL))
{
wv.loadURL("javascript: ....");
}
}
public Class Wait()
{
Boolean pageLoaded = false;
Wait waiting = this;
public boolean waitForPage(wv,URL)
{
wv.setWebViewClient(new WebViewClient()
{
public void onPageFinished(WebView webView, String url )
{
pageLoaded = true;
synchronized(waiting)
this.nothifyAll();
}
});
wv.loadURL(URL);
synchronized(this) // --> End up in an Endless Loop
this.wait();
if(pageLoaded)
return true;
return false;
}
}
Does anybody know why it doesn't get synchronized and finally end up in an endless Loop? Maybe I use the wrong eventhandler?
The this.wait(); seems to be like an While(true) verifying on a Boolean set by NoifyAll(). Please some Idea, how I can wait for these Events and Hold the program flow until the event is fired!
The
thisinsynchronized(this)inside theonPageFinished()method refers to theWebViewClientinstance, while thethisinsynchronized(this)afterwv.loadURL(URL)refers to theWaitinstance.Consider using the utilities in Android's java.util.concurrent package