The Java object that is bound runs in another thread and not in the thread that it was constructed in.
Now you now want to save PageContent
main_webview1_savewebpage (B4A line: 49)
Msgbox("2","")
android.view.ViewRoot$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
at android.view.ViewRoot.checkThread(ViewRoot.java:2802)
at android.view.ViewRoot.requestLayout(ViewRoot.java:594)
at android.view.View.requestLayout(View.java:8125)
at android.view.View.setFlags(View.java:4501)
at android.view.View.setVisibility(View.java:3030)
at android.app.Dialog.hide(Dialog.java:254)
at anywheresoftware.b4a.debug.Debug.wait(Debug.java:178)
at anywheresoftware.b4a.debug.Debug.reachBP(Debug.java:223)
at anywheresoftware.b4a.debug.Debug.ErrorCaught(Debug.java:112)
at b4a.savehtml.main._webview1_savewebpage(main.java:400)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:105)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:89)
at uk.co.martinpearman.b4a.jsinterface.JSInterface$1B4AJSInterface.CallSub(JSInterface.java:79)
at android.webkit.BrowserFrame.stringByEvaluatingJavaScriptFromString(Native Method)
at android.webkit.BrowserFrame.stringByEvaluatingJavaScriptFromString(Native Method)
at android.webkit.BrowserFrame.loadUrl(BrowserFrame.java:245)
at android.webkit.WebViewCore.loadUrl(WebViewCore.java:1562)
at android.webkit.WebViewCore.access$1400(WebViewCore.java:52)
at android.webkit.WebViewCore$EventHub$1.handleMessage(WebViewCore.java:948)
at android.os.Handler.dispatchMessage(Handler.java:99)
at anywheresoftware.b4a.Msgbox.waitForMessage(Msgbox.java:196)
at anywheresoftware.b4a.Msgbox.msgbox(Msgbox.java:127)
at anywheresoftware.b4a.keywords.Common.Msgbox2(Common.java:404)
at anywheresoftware.b4a.keywords.Common.Msgbox(Common.java:371)
at b4a.savehtml.main._webview1_savewebpage(main.java:394)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:105)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:89)
at uk.co.martinpearman.b4a.jsinterface.JSInterface$1B4AJSInterface.CallSub(JSInterface.java:79)
at android.webkit.BrowserFrame.stringByEvaluatingJavaScriptFromString(Native Method)
at android.webkit.BrowserFrame.stringByEvaluatingJavaScriptFromString(Native Method)
at android.webkit.BrowserFrame.loadUrl(BrowserFrame.java:245)
at android.webkit.WebViewCore.loadUrl(WebViewCore.java:1562)
at android.webkit.WebViewCore.access$1400(WebViewCore.java:52)
at android.webkit.WebViewCore$EventHub$1.handleMessage(WebViewCore.java:948)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.webkit.WebViewCore$WebCoreThread.run(WebViewCore.java:621)
at java.lang.Thread.run(Thread.java:1096)
android.view.ViewRoot$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
public boolean RunOnGuiThread(String sub, Object[] params)
{
sub = sub.toLowerCase();
if (params == null)
params = new Object[0];
if (!ba.subExists(sub))
{
return false;
}
ba.raiseEventFromDifferentThread(this, this, 0, sub, true, params);
return true;
}
private BA activity;
public String CallSub(String subName, String param1, String param2) {
subName = subName.toLowerCase();
Object[] params = { param1, param2 };
return (String) activity.raiseEvent(this, subName, params);
}
private BA activity;
private int taskId = 0;
private String CallSubOnGUIThread(String subName, Object[] params) {
subName = subName.toLowerCase();
if (params == null) {
params = new Object[0];
}
if (activity.subExists(subName)) {
return (String) activity.raiseEventFromDifferentThread(this, this, taskId++, subName, true, params);
} else {
return "debug Sub does NOT exist";
}
}
public String CallSub(String subName, String param1, String param2) {
subName = subName.toLowerCase();
Object[] params = { param1, param2 };
return CallSubOnGUIThread(subName, params);
}
No as long as the limitations are acceptable.Is there any reason why i shouldn't simply update the library so that all existing BA.raiseEvent method calls simply use the BA.raiseEventFromDifferentThread method instead?