Based on a previous thread (https://www.b4x.com/android/forum/t...area-while-running-a-long-computation.133906/), I'm looking for the best way to handle long running tasks.
Putting Sleep calls here and there, while functional, looks like a way to somewhat putting something extraneous to the core algorithm you're going to implement.
Is there a way to run the code in a different thread, so the main one could handle the UI without hunging up?
Something akin to a Service module from B4A?
Yes. You should be able to use my Threading library in B4J to offload the task to another thread. Although originally written for B4A it is Java rather than Android specific.
This library lets you run Basic4android Subs on separate threads to the main GUI thread. It also contains a Lock (semaphore) object that can be used for resource access arbitration and thread synchronisation. Included is also an enhanced Exception object to give more information on any...
B4J use is simpler than B4A as you don't have to worry about Activity lifetime issues leaving threads hanging. Erel doesn't seem to like threading (except when it is his Async functions doing it ) but I've never seen any problems using it. Doesn't work nicely in debug mode though!
I think you need to know what you are doing when handling threads, most of the time people will use it when there are more b4xish solutions, like async and callsubdelayed that will do the job without hassle.
But if you think you can benefit from threads, try it.