Hi agraham.
That code works perfectly and the message boxes now display as expected.
So i'm looking at updating the JSInterface library and have a question...
Here's part of the current (version 1.3) library code:
private BA activity;
public String CallSub(String subName, String param1, String param2) {
subName = subName.toLowerCase();
Object[] params = { param1, param2 };
return (String) activity.raiseEvent(this, subName, params);
}
That's the overloaded CallSub method that accepts two String parameters.
To test out your posted code i did this:
private BA activity;
private int taskId = 0;
private String CallSubOnGUIThread(String subName, Object[] params) {
subName = subName.toLowerCase();
if (params == null) {
params = new Object[0];
}
if (activity.subExists(subName)) {
return (String) activity.raiseEventFromDifferentThread(this, this, taskId++, subName, true, params);
} else {
return "debug Sub does NOT exist";
}
}
public String CallSub(String subName, String param1, String param2) {
subName = subName.toLowerCase();
Object[] params = { param1, param2 };
return CallSubOnGUIThread(subName, params);
}
That code works fine.
Version 1.3 of JSInterface has four overloaded
CallSub methods that can handle from zero up to three String parameters.
The methods all use the
BA.raiseEvent method to call the B4A Sub.
Now i can't see it being a good idea to keep the existing CallSub methods which do not work with the UI thread and then adding more methods that are UI compatible.
It'd be a bit much i think to expect the user to research the subject and decide whether their javascript needs to call a Sub which is UI compatible or not.
Plus it'd also bloat the library with much repeated code.
[question]
Is there any reason why i shouldn't simply update the library so that all existing
BA.raiseEvent method calls simply use the
BA.raiseEventFromDifferentThread method instead?
So even if a javascript interface method does NOT need to access the UI, the UI compatible raiseEventFromDifferentThread is used anyway.
[/question]
Thanks.
Martin.