Comments (3)
Hmm... I think the best way to do that currently is to define a global JS object with a method that calls the desired callback, then use the Duktape.proxy()
method to create an object that can be called from Java. You could also use the evaluate method to invoke the callback directly: Duktape.evaluate("setTimeout(10)");
We don't provide a way to call a free (non-member) function from Java.
from zipline.
@ntrrgc did you end up finding a good way to implement setTimeout?
@szurbrigg would it be possible to provide a little more clarification on what you mean?
I currently exposed "setTimeout" as a global to JS which I have implemented as so:
public class SetTimeout implements ISetTimeout {
private Handler handler;
private HashMap<Integer, Runnable> timerMap;
public SetTimeout(Handler handler, HashMap<Integer, Runnable> timerMap) {
this.handler = handler;
this.timerMap = timerMap;
}
@Override
public int setTimeout(Object function, int delay) {
Runnable task = new Runnable() {
@Override
public void run() {
//need to callback the function here
}
};
int id = task.hashCode();
timerMap.put(id, task);
handler.postDelayed(task, delay);
return id;
}
}
Then calling:
duktape.set("setTimeout", ISetTimeout.class, new SetTimeout(handler, timerMap));
Where ISetTimeout is defined as:
public interface ISetTimeout { int setTimeout(Object function, int delay); }
Obviously this crashes because of the function being passed as a parameter to the method. What is the recommended way around this?
from zipline.
@twhit093 No, I ended up rolling my own JavaScript bridge for Android that allows holding references to JS objects from Java (including functions) and therefore is capable of these things. https://github.com/ntrrgc/jsvm
from zipline.
Related Issues (20)
- Crash: FileNotFoundException while attempting to fetch manifest from disk cache HOT 1
- SQLiteReadOnlyDatabaseException in ZiplineLoader cache HOT 2
- Stack Overflow after 1.2.0, because of shared commit. HOT 6
- macosX64Test tests fail due to ‘KryoException: Buffer underflow.’ in Gradle HOT 1
- Production builds' stacktraces are terrible HOT 2
- After 1.2.0 Always getting java.lang.StackOverflowError: stack size 1039KB, HOT 4
- Defer task creation in Gradle plugin
- NoSuchElementException in ZiplineApis.rewritePair HOT 1
- Evaluate new QuickJS release
- Add `-fwrapv` to compile args
- zipline-cryptography needs Linux support
- zipline-cryptography needs a better lookup API
- zipline-cryptography Random API improvements
- ziplineApiDump doesn’t work with the configuration cache
- Ensure our builds are 16kb compliant
- Enable QuickJS's `BigFloat` extensions HOT 1
- Enable file integrity checks on Android
- Get fresh code after a crash
- `FreshnessChecker` broke the ability to embed online applications HOT 1
- Serializer for SerializableZiplineServiceType is not found. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from zipline.