In a webview, I would like to wrap two things in one blocking function:
I have the following:
public class WebBikeWebView extends WebView {
private String mData;
public WebBikeWebView(Context context) {
super(context);
// result of loadUrl() returns here in this call-back, in message
this.setWebChromeClient(new WebChromeClient() {
@Override
public boolean onJsAlert(WebView view, String url, final String message, JsResult result) {
Log.d("LogTag", message);
mData = message;
result.confirm();
return true;
}
});
}
// I would like to create a blocking method like this:
public String getValue(final String name) {
String code = "javascript:alert(' + " name + "')";
this.loadUrl(code);
ret = mData; // problem is that mData is a result from the call-back onJsAlert()
return ret;
}
}
I would like the getValue()
method to be a synchronous/blocking method.
It's a bit like using wait/notify on the same thread. I did tried wait/notify, but the control stops fetching the data as this interrupts the current thread.