Android Question Best way to implement "CallSubNext"

SteveTerrell

Active Member
Licensed User
Longtime User
I have a Sub that is run to handle messages from call back code from Timers, Touch events etc. This Sub can take some time to run 10s of ms and can change the screen contents. Possibly for no good reason i do not want the Sub to run as a direct call from the call back code.

To me it seems much better if my Sub runs after the call back has returned from my code (to B4A?).

I believe that CallSubDelayed would do this. I do not need the Activity is active check as the Sub is in a service.

I can also see that enabling a specific short (1ms or perhaps 0ms?) timer (where i have full control over the call back code so I am not worried about Sub executing in that call back) could also achieve this function. This would be something like the CallSubPlus but not creating a new timer each time.

There is also of course also CallSubPlus with a very short delay.

Question: Can anyone advise which solution (or a different solution) gives the shortest execution time overhead and the shortest delay to running Sub after the original call back returns to B4A.
 

SteveTerrell

Active Member
Licensed User
Longtime User
You should use CallSubDelayed. The sub will be executed once the main thread is free to process the message queue.
Thanks,

Just experimented with timer interval set to 0 and get an "interval must be larger than 0" crash - it may be worth mentioning that in the Timer docs.
 
Upvote 0
Top