B4J Question Ui updating

JTmartins

Active Member
Licensed User
Longtime User
I need to process a few folders inside a loop, and cant give the user a feedback of the folder being processed, as all UI is only updated at the end of the loop.

The process can take a few minutes, specially because the folders are quite big and are online shared..So apparently there is no easy way to tell the user what is being processed, as I would like to.

Any trick to do update the UI while stuff is being done ?

Many thanks
J
 
Last edited:

Roycefer

Well-Known Member
Licensed User
Longtime User
You have a couple options.
  1. You can do the heavy lifting in another Thread and occasionally send commands to update the UI to the Main Thread. This will require the Threading library and using Thread.RunOnGuiThread().
  2. Divide the task into blocks and do the heavy lifting in blocks using CallSubDelayed:
B4X:
Sub HeavyLifting(block as int)
   'Some heavy stuff
   '....
   UpdateUI
   If block<MaxBlocks Then CallSubDelayed2(Me, "HeavyLifting", block+1)
End Sub
 
Upvote 0

jmon

Well-Known Member
Licensed User
Longtime User
I think Roycefer solution number 2 is the best. Another solution for that is:

3. you could also write a separate jar file and execute it with jShell.RunWithOutputEvents. You can then read the _StdOut and _StdErr events and update the UI according to those raised events.

 
Upvote 0

BPak

Active Member
Licensed User
Longtime User
Wait For needs Event. Can an event be created to replace say a boolean var?

I have been using boolean var global to test in timer for downloading many xml files consecitively!
 
Upvote 0
Top