B4J Question Best way to handle long running subs

Alessandro71

Well-Known Member
Licensed User
Longtime User
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?
 

agraham

Expert
Licensed User
Longtime User
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.

 
Upvote 0

agraham

Expert
Licensed User
Longtime User
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!
 
Upvote 0

EnriqueGonzalez

Well-Known Member
Licensed User
Longtime User
Erel doesn't seem to like threading
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.
 
Upvote 0
Top