I need more like a pause statement. I do not have one statement, I actually have nearly 10-12 statements in my code. Having timer to do it will be complicated. Thanks
You can create a sub (private or public) and call it with the time you want.
B4X:
.........
........
........
Astream.Write ("abcabc")
Sleep (25)
...........
..............
..............
Sub Sleep(milliseconds As Long)
Dim t, Actual As Long
Actual = DateTime.Now
t= Actual
Do Until (t-Actual) >= milliseconds
t= DateTime.Now
DoEvents
Loop
End Sub
As suggested, use a Timer if you want to retry an operation or continue after a certain time, not a DoEvents loop because DoEvents have many side effects due to some events not processed. Try to rotate the device during a DoEvents loop and you'll understand.
The Timer, depending on what you call it will have a :
Sub MyTimer_Tick
End Sub
And the beauty of the Timer is that it works in it's own thread.
So it doesn't block the main thread.
It is 'non-blocking'
One thing to keep in mind then is that as soon as you enable the timer, off it ticks on it's own thread and when it counts down to zero depending on the number of milliseconds that you have set it to, it will fire the MyTimer_Tick Sub.
You must program with this in mind and put the code that you wish to run when the Timer count's down to zero in that MyTimer_Tick subroutine and it is often the case that you will include a MyTimer.Enabled = False line in that subroutine and somewhere else in your code you will put a MyTimer.Enabled = True to fire it off.
The MyTimer_Tick subroutine can be seen as an interrupt driven subroutine
A paused activity mainly means that no control events are triggered.
The easiest way, in my opinion, to achieve this, without blocking the thread, is to place a transparent panel, bring it to front, consume its click/touch, and run a timer to continue the way you want. When finished, hide the panel.