I am using rhino-android library to invoke java script code in java but I am not getting how to handle callback in javascript in java.
Java script code
function TestingFunction(data, callback ){
callback(data);
}
I am trying to invoke the same in java- Android code
invocable.invokeFunction("TestingFunction","12345", ?(How to handle callback))
Can anyone suggest how to handle callback from javascript in java code?
Passing a Java callback to a JavaScript function in Rhino should be possible by implementing the org.mozilla.javascript.Function
interface, something like this:
invocable.invokeFuntion("TestingFunction", "12345",
new org.mozilla.javascript.Function() {
@Override
public Object call(Context cx, Scriptable scope, Scriptable thisObj,
Object[] args) {
String data = (String) args[0];
// do stuff...
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.