Does somebody know a way execute a task via a script that doesn’t freeze LL while it’s being executed?
Does somebody know a way execute a task via a script that doesn’t freeze LL while it’s being executed? I’ve tried posting runnables on the view of a container, but it doesn’t help.
Thanks in advance 🙂
]]>« respotet for Kustom LWP (Previous Post)
(Next Post) Hi all, here is my template “Summer of Fjord”! »
< ![CDATA[
http://www.lightninglauncher.com/scripting/reference/api/reference/net/pierrox/lightning_launcher/script/api/Window.html#setTimeout(java.lang.Object,%20int)
]]>
< ![CDATA[
Tried that before runnables, also freezes LL
]]>
< ![CDATA[
If you can split your task into several smaller, you can call subsequent setTimeout calls to prevent a freeze. Otherwise use Thread or AsyncTask.
]]>
< ![CDATA[
I just tried to do this, but I have to extend a Java class and override on of its methods and I don’t really know how to do that. This is wat I tried:
LL.bindClass(“java.lang.Thread”)
var TestThread = function(){
this.run = function(){
log(“test”)
}
}
TestThread.prototype = Thread;
var testThread = new TestThread()
testThread.start()
It can’t find the start method in Thread
]]>
< ![CDATA[
LL.bindClass(“java.lang.Thread”);
LL.bindClass(“java.lang.Runnable”);
new Thread(new Runnable(){
run:function(){
…
}
}).start();
]]>
< ![CDATA[
that crashes LL for me…
]]>
< ![CDATA[
Colin de Roos
then your function is not valid.
]]>
< ![CDATA[
the function was it.setLabel(“test”) and “it” is directly pulled from the event that launches the script, which is a long tap on the item. If that’s not valid i don’t know what is
]]>
< ![CDATA[
i did read something about that it’s bad for u to try to update a gui outside of the guithread, so maybe that’s the problem?
]]>
< ![CDATA[
Colin de Roos
very likely yes.
]]>
< ![CDATA[
Hmm, do you think it’s still worth trying with AsyncTask?
]]>
< ![CDATA[
I confirm that Android UI is not designed to be accessed from several threads at once, and Lightning isn’t neither. Each time you need to change some UI related stuff, you need to do it on the UI thread. One way to do this is using a Handler created before to start the thread (that is: on the UI thread), and in the other thread use handler.post(new Runnable() { the code to execute});
]]>
< ![CDATA[
yes i came up with that last night too. Gonna try that now.
]]>
< ![CDATA[
Seems to work! Thanks a lot guys!
]]>