Hi Cableguy.
I'm afraid i simply did not have the time to put together a better demo for WebViewExtras - work has to come before play!
Anyway you can use the JSInterface examples/demo as a basis for working with the newer WebViewExtras.
You just have to take into account a couple of changes:
1) The interface's CallSub() method signature has changed.
With JSInterface the CallSub() signature was:
CallSub(subName As String)
CallSub(subName As String, parameter1 As String)
CallSub(subName As String, parameter1 As String, parameter2 As String)
CallSub(subName As String, parameter1 As String, parameter2 As String, parameter3 As String)
The CallSub() signature in WebViewExtras is
CallSub(subName As String, callUIThread As boolean)
CallSub(subName As String, callUIThread As boolean, parameter1 As String)
CallSub(subName As String, callUIThread As boolean, parameter1 As String, parameter2 As String)
CallSub(subName As String, callUIThread As boolean, parameter1 As String, parameter2 As String, parameter3 As String)
Both JSInterface and WebViewExtras add an interface with a CallSub() method that your javascript can call with
none,
one,
two or
three String parameters.
WebViewExtras requires an extra boolean parameter though
callUIThread.
If the B4A Sub that your javascript calls modifies your activity user interface then you must pass
true for the value of callUIThread.
If the B4A Sub does not modify the UI then you can pass true or false as callUIThread.
However a Sub called with callUIThread as true cannot return any values from your activity to the javascript.
If callUIThread is false then values can be returned from your activity to the javascript.
The JSInterface CallSub() method can be pictured as if the callUIThread parameter is hardcoded to false.
With JSInterface your javascript is unable to call a B4A Sub that modifies the activity user interface.
Here's a thread that might help explain it all:
http://www.b4x.com/forum/basic4android-updates-questions/11099-jsinterface-problem-msgbox.html
2) I refactored
execJS() in JSInterface to
executeJavascript() in WebViewExtras.
To answer your original question:
You can run the JSInterface examples with WebViewExtras by simply adding the false callUIThread parameter to your javascript:
B4A.CallSub('MyB4ASub', false, 'some string value')
You will need to structure your B4A code so that Subs that return values to javascript do not modify the activity UI.
Martin.