Hi again.
I have fixed all the bugs etc and it's working perfectly!
I've spent the morning implementing it in an app where i need to save data from a WebView so on orientation change i can restore the WebView exactly.
As a library the class adds four new methods to your application:
Methods that can be called from javascript: 'CallSub0', 'CallSub1' and 'CallSub2'.
And a single method that can be called from your B4A activity 'execJS'.
execJS accepts a single string as an argument - the string is a javascript statement to be executed.
Example:
myJSInterfaceInstance.execJS("location.href='http://google.com'")
That doesn't look very useful and can be done without the interface, but more obvious uses of execJS would be to call a javascript function in your webpage.
Lets say your app has data for your WebView to process, but the WebView has no idea that new data is available
Javascript function:
function updateData(){
var newData=B4A.CallSub0('getData');
// process newData
}
B4A sub:
Sub getData As String
' return a JSON string to the WebView
Dim myStr As String
' process myStr so it contains the JSON data
Return myString
End Sub
B4A code to call when your app has data ready for your WebView:
myJSInterfaceInstance.execJS("updateData()")
No need to use events as B4A can execute any javascript within the WebView and the WebView can execute any B4A sub.
Shall i update this thread with a final post containing the library or shall i start a new thread on the
Additional libraries forum?
A new thread sounds best and will give me a chance to properly document the library?
Martin.