ericwlange / AndroidJSCore

AndroidJSCore allows Android developers to use JavaScript natively in their apps.
468 stars 78 forks source link

How can I cancel evaluateScript execution on infinite loops? #43

Closed tharvey closed 5 years ago

tharvey commented 8 years ago

I'm needing a way to break out of the execution of evaluationScript. In my use case I'm executing code which may loop forever. Is there an exit condition I can set somewhere?

Tim

ericwlange commented 7 years ago

The way it is currently designed, there is no built-in way to do that. If you need that kind of functionality, I suggest that you create a Thread in which the JS code runs. Any interactions you have with JS will need to occur in that thread, which may mean that you have to post messages to the thread from other threads to interact with JS. When you want to kill the running JS, you would call Thread.interrupt() on your JS thread.

This is untested and potentially dangerous. I would suggest not writing code that may loop forever as a first choice.