Running into a problem in that my code works in debug, but not in release. b4a980
I have an activity that uses webview extras to inject javascript and get the source HTML. It works great in debug. However, the routine webpagehtml crashes in release mode with the error below. So I have two questions. Why the difference between debug and release? Second, how can I restructure the code to make this work. I did research and discovered the problem can occur in pure Java, and their solution is to launch the webview.loadurl on the UI thread. Can this be done in B4A?
Help!
java.lang.RuntimeException: java.lang.Throwable: A WebView method was called on thread 'JavaBridge'. All WebView methods must be called on the same thread. (Expected Looper Looper (main, tid 1) {fd95b0d} called on Looper (JavaBridge, tid 3268) {997c056}, FYI main Looper is Looper (main, tid 1) {fd95b0d})
I have an activity that uses webview extras to inject javascript and get the source HTML. It works great in debug. However, the routine webpagehtml crashes in release mode with the error below. So I have two questions. Why the difference between debug and release? Second, how can I restructure the code to make this work. I did research and discovered the problem can occur in pure Java, and their solution is to launch the webview.loadurl on the UI thread. Can this be done in B4A?
Help!
Pure Java solution webview.post:
private void test(final String s) {
webView.post(new Runnable() {
public void run() {
webView.loadUrl("javascript:" + s + ";");
}
});
System.out.println("javscript done..");
}
java.lang.RuntimeException: java.lang.Throwable: A WebView method was called on thread 'JavaBridge'. All WebView methods must be called on the same thread. (Expected Looper Looper (main, tid 1) {fd95b0d} called on Looper (JavaBridge, tid 3268) {997c056}, FYI main Looper is Looper (main, tid 1) {fd95b0d})
Activity Code:
Sub WebView1_PageFinished (Url As String)
' Call the javascript injection routine to get the HTML
WebView1.JavaScriptEnabled = True
ExtractHTMLViaJavascript
End Sub
Sub ExtractHTMLViaJavascript
' Create an outerHTML directive and send it to webpagehtml()
Dim Javascript As String
Javascript = "B4A.CallSub('webpagehtml', false, document.documentElement.outerHTML)"
WebViewExtras1.executeJavascript(Javascript)
' Extracted value ends up in webpagehtml() via the callback
End Sub
Sub webpagehtml (strhtml As String)
' Capture the web page HTML as a return value from the injected Javascript
If CheckForNoVehiclesFound (strhtml) = True Then
WebView1.Visible = False
Else
WebView1.Visible = True
End If
End Sub
Sub ExtractHTMLViaJavascript
' Create an outerHTML directive and send it to webpagehtml()
Dim Javascript As String
Javascript = "B4A.CallSub('webpagehtml', false, document.documentElement.outerHTML)"
WebViewExtras1.executeJavascript(Javascript)
' Extracted value ends up in webpagehtml() via the callback
End Sub