The android user interface must only be modified by code running in the main application thread - it must not be modified by code running in a background thread.
The JavascriptInterface might or might not be executed in the main application thread - there is no guarantee that it will always be executed in any particular thread.
If your javascript calls a b4a sub that does not modify the UI then the value of the JavascriptInterface CallSub 'callUIThread' parameter is unimportant - a value of True or False can be used:
Sub after
Dim i As Int
i=123
End Sub
The 'after' sub here does not modify the UI.
BUT your 'after' sub executes javascript that changes the content of a form field being displayed in the WebView - the UI is being modified.
So you must tell the JavascriptInterface that the UI is going to be modified in the sub called by CallSub.
The JavascriptInterface then ensures that the b4a sub is called in the main application thread.
So modify the javascript CallSub statement so it passes true as the callUIThread parameter and you'll have no need to use CallSubDelayed:
Sub Process_Globals
End Sub
Sub Globals
Dim JavaScript As WebViewExtras
Private WebView1 As WebView
End Sub
Sub Activity_Create(FirstTime As Boolean)
WebView1.Initialize("WebView1")
Activity.AddView(WebView1,0,0,100%x,100%y)
JavaScript.addJavascriptInterface(WebView1,"B4A")
WebView1.LoadUrl("http://gozine2.ir/Specialforms/viewapproximation.aspx")
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub WebView1_PageFinished (Url As String)
Log("FINISHED")
JavaScript.executeJavascript(WebView1,"B4A.CallSub('Process_HTML', true, document.documentElement.outerHTML)")
End Sub
Sub Process_HTML(Html As String)
Log("Extracted")
JavaScript.executeJavascript(WebView1,"document.getElementById('MainContent_cmbField').value='"&"3"&"';")
ToastMessageShow("set",False)
End Sub
Martin.