I am calling JavascriptInterface method from webview to call javascript methods. The problem is method returns value before getting result value. So how can I make return statement wait till javascript method is executed from ui thread.
JavascriptInterface
public class CordovaJSInterface {
Context cxt;
String returnValueFromJS="";
CordovaJSInterface(Context cxt){
this.cxt = cxt;
}
public void setReturnValueFromJS(String valueFromJS){
this.returnValueFromJS = valueFromJS;
}
@JavascriptInterface
public String performClick()
{
/*MainActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
mainView.loadUrl("javascript:" + "getLocation()" + ";");
}
});*/
mainView.post(new Runnable() {
@Override
public void run() {
mainView.loadUrl("javascript:" + "getLocation()" + ";");
}
});
/**PROBLEM : Method returns variable returnValueFromJS
* before it is updated by getLocation() javascript method..
**/
return returnValueFromJS;
}
So I want performClick() to let ui thread complete first and then return value.