While this does seem to explain things, the documentation doesn’t specify that there’s a difference in Android, embarrassed to say I scoured the issues but only looked at open ones to see if any present open bugs were documenting this, not closed ones, and missed that as a result.
If I call xojo.execute("test")
within the javascript of the HTML without doing it through ExecuteJavaScript()
I seem to get “Java exception was raised during method invocation”. If I call xojo.execute("test");
within ExecuteJavaScript()
nothing appears to happen but JavaScriptResult
is fired, at the moment I tried to place it within a button and click that. I would expect that JavaScriptRequest
would be triggered as a result of xojo.execute()
based on documentation and that issue linked which is what I mean by ‘nothing seems to happen’ I have a messagebox defined within JavaScriptRequest
which is never fired when xojo.execute
is called.
For clarity this is what I have in my button as a test:
Dim JsCode as String JsCode = "xojo.execute('test'); WebViewer.ExecuteJavaScript(JsCode)
When I’m trying to execute it from the HTML directly, I also tried defining a function in Javascript via the DocumentComplete event, and then calling that function on click within my HTML page. The function does fire but xojo.execute()
fails. Beyond that I’ve tried just directly calling xojo.execute()
without defining the function utilizing ExecuteJavaScript
(assuming that by defining it with ExecuteJavaScript
that if it needed to be ‘created’ by Xojo it would have the proper reference to the object but maybe wishful thinking.
It seems you’ve been able to get this to work in the past though based on the history on the linked issue, so I’m curious what your test case was or if this is bugged in a later version and hasn’t been tested. At this point I’ve sort of moved on from using Xojo for what I’m trying to accomplish but still curious if I’m doing something wrong.
Also,
It’s unfortunate the documentation hasn’t been kept up to date on this, I know the Android support is still ‘beta’ but I recall when this stuff was reliable for RealBasic:
MobileHTMLViewer — Xojo documentation.
I’ve mostly only used Xojo for raspberry pi projects recently to prototype things quickly instead of relying on something like C#, but was hoping I could run it here as C# doesn’t run on android without Xamarin and stuff.
UPDATE: I was mistaken, and Martin T has kindly corrected me below. The documentation does briefly mention a difference for android, but it’s not clear and I think it should be improved.
Additionally, I discovered my issue WAS that I was executing a MessageBox within JavaScriptRequest
it appears this runs on a JavaScriptBridge thread not the main application/UI thread meaning anything that interfaces with the UI here will fail, running logcat revealed this was what was going wrong when it was being called and why I was seeing the Java Invocation Exception thing.
So, it does appear to work if I do the following:
- Define a function via
ExecuteJavaScript
within the WebViewer on DocumentComplete
event.
- Call the function via my javascript in the HTML page that I’ve defined in step 1.
I have not tried simply executing xojo.execute
without first defining the function via ExecuteJavaScript
yet but it does seem the implementation is there and does work as intended just not well documented in my opinion.
I also haven’t tested with parameters yet.