Android Question Stop Brain

antonio.murtino

Member
Licensed User
Longtime User
I melted , I puzzled to find a solution that actually should not be sought , why ?, in developing an app , I came across a condition that I did not expect . In essence it is a classic Do Until/ loop , from which comes out when the value of a variable changes , do not understand , but you point in a strange way , in the various languages adopted in time, where these common cycles are normally used , here block any activity , even if I have vague memories , or to have them already used in B4A and seeing them work properly , place a simplified code :

B4X:
Sub Start As Boolean
    ucc=0
    Do Until ucc=1
     DoEvents
    Loop
End Sub

Sub Button1_Click
    ucc=1
    DoEvents
    Msgbox (ucc,"Valore")
End Sub

in essence , is called the sub Start , this should ' loopare ' until the value of the UCC variable does not change , then this variable should be modified simply by clicking on the button , the Click event when it takes the action , then you should get out of the loop and return to the point next to the call of the Sub Start .

Well , it does not come out piuuuuuù , although it denotes the pressure button . In any language that respects I used this form to make sure that a certain condition had occurred and then resume from the next .

That idea you have on the matter ?
 

marcick

Well-Known Member
Licensed User
Longtime User
My two cents:
unless the condition is met for sure in a very short time, it is not a good programming practic here in B4A (and i suppose in Java/eclipse) to use Do-Until-Loop.
The main disadvantage is that during the loop the UI is frozen (you can't update graphics) and if I'm not wrong also the click event is not fired.
Also the OS could stop your app if it not responsive for a long time.
Also DoEvents I have learned it's better to forget it exists and never use it because it doesn't behave as you expect coming from VB or other languages.
Better to find other way using services or timers.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…