Android Question system locked in while loop

Pedro Caldeira

Active Member
Licensed User
Longtime User
Hello,
I am developing a system to interact with an automated payment machine, and ned the execution of the app to wait for s given return status, but my loop cycle hangs the app.

I have a button in the interface that sets GloryStatus = 1 and the response for the machine sets GloryStatus = 0.
It should just update the TotalPament while GloryStatus = 2, why is it hanging the App.
I amd running the App in Ubuntu, by the way.

B4X:
Sub ProcessPayment

    CurrentPage=4
    SetPages
    GloryStatus = 2 ' em standBy
    Talk2Glory("Pay" , TotalPayment)
    lblValorPagar.text=NumberFormat2(TotalPayment,1,2,2,False) & " €"

    Do While GloryStatus = 2
        lblValorPagar.text=NumberFormat2(TotalPayment,1,2,2,False) & " €"
    Loop

    If GloryStatus = 1 Then
        tituloMensagem.Text = "Pagamento Abortado"
        lblMensagem.Text = "Por favor recolha o cartão e o seu dinheiro."
        showMensagem
        Talk2Reader("EjectCard")
        Talk2Glory("CancelPay", Null)
        CurrentPage = 1
        SetPages
    Else If GloryStatus = 0 Then
        Talk2WinREST("SetPayment",Null)
        Sleep(1000)
        PaymentAmount = TotalPayment
        Talk2WinREST("ProcessPayment",Null)
        'volta ao ecran inicial
        CurrentPage = 1
        SetPages
    End If

End Sub
 

KMatle

Expert
Licensed User
Longtime User
Do While GloryStatus = 2
lblValorPagar.text=NumberFormat2(TotalPayment,1,2,2,False) & " €"
Loop

Don't use loops for a wait sequence like this. Better use a timer which checks the status from time to time.

How does "the machine" set the status?
 
Upvote 0

Pedro Caldeira

Active Member
Licensed User
Longtime User
Don't use loops for a wait sequence like this. Better use a timer which checks the status from time to time.

How does "the machine" set the status?

ir writes a xml with the response,
but for debug purposes I have a couple buttons that set the status
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
Doing a do while loop like that though eats up processing resources like mad. You're pretty much pegging out you processing power and making everything else unresponsive. You might as well have written an endless loop. Since you're already using sleep in the Else If section, just throw one in here too (your UI and event queue will love you for it).
 
Upvote 0

eps

Expert
Licensed User
Longtime User
or just have an Event that does the processing? Why are you looping waiting for something, it makes no sense.
 
Upvote 0
Top