Android Question It is possible to wait for a B4XPages page to disappear? {Solved]

carlos7000

Well-Known Member
Licensed User
Longtime User
Hello, I would like to know if it is possible to wait for a B4XPages (QrCode Reader) page to finish and then obtain the result.

The first thing I do is load the page that reads in qrcode

B4X:
Private Sub ButtonQrOrigen_Click
    B4XPages.ShowPage("Qr Code Reader")
    Dim Resultado As String = QRC_Reader.Resultado
    Log($"Resultado ${Resultado}"$)
End Sub

As we know, all the code of the function is executed without waiting for the result

When the reader captures the text and the FoundBarcode function is executed, the page closes with the line B4XPages.ClosePage(Me)

B4X:
Private Sub FoundBarcode (msg As String)
    lblResult.Text = msg
    toast.Show($"Found [Color=Blue][b][plain]${msg}[/plain][/b][/Color]"$)
    B4XPages.ClosePage(Me)
End Sub

As the title says, is it possible to wait for the page Disappear, unload, etc or not?

I need to show the qr code reader several times. Is it possible to do it as a Wait? If not, how else do you suggest I do it?
 
Solution
B4X:
'In page x

Private Sub Button1_Click
    pagOne.CallingPage = Me
    pagOne.CallingPageEvent = "SomeName"
    B4XPages.ShowPage("pagOne")
    Wait For SomeName
    Log("Completed")
End Sub

B4X:
'In "pagOne" - your "scanning page"

Sub Class_Globals
    Private Root As B4XView 'ignore
    Private xui As XUI 'ignore
   
    Public CallingPage As Object
    Public CallingPageEvent As String
End Sub


Private Sub B4XPage_Disappear
    CallSubDelayed(CallingPage, CallingPageEvent)
End Sub

epiCode

Active Member
Licensed User
You can put the code in:

B4X:
Private Sub B4XPages_Disappear
    
End Sub
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
B4X:
'In page x

Private Sub Button1_Click
    pagOne.CallingPage = Me
    pagOne.CallingPageEvent = "SomeName"
    B4XPages.ShowPage("pagOne")
    Wait For SomeName
    Log("Completed")
End Sub

B4X:
'In "pagOne" - your "scanning page"

Sub Class_Globals
    Private Root As B4XView 'ignore
    Private xui As XUI 'ignore
   
    Public CallingPage As Object
    Public CallingPageEvent As String
End Sub


Private Sub B4XPage_Disappear
    CallSubDelayed(CallingPage, CallingPageEvent)
End Sub
 
Last edited:
Upvote 0
Solution

toby

Well-Known Member
Licensed User
Longtime User
The code below keeps the page open until the user taps "Close the page" button. This is what you want if I understand you correctly. You need to define dialog in the class_Globals
B4X:
dim dialog as b4xDialog
At the end of B4xPage_Create, add:
B4X:
Private Sub B4XPage_Created (Root1 As B4XView)
'....
    dialog.initialize(root)
End Sub

B4X:
Private Sub FoundBarcode (msg As String)
    lblResult.Text = msg
    
    Wait For (dialog.Show($"Found [Color=Blue][b][plain]${msg}[/plain][/b][/Color]"$,  "OK", "", "Close the page"))complete(intResult As Int)
    If intResult=xui.DialogResponse_Cancel Then
        B4XPages.ClosePage(Me)
    End If
End Sub
 
Upvote 0

carlos7000

Well-Known Member
Licensed User
Longtime User

The code worked very well.

Thank you so much.

The following code confuses me.

B4X:
Private Sub B4XPage_Disappear
    CallSubDelayed(CallingPage, CallingPageEvent)
End Sub

How can you call the event someName. It seems to me that someName does not exist.

Please explain me the code
 
Upvote 0

carlos7000

Well-Known Member
Licensed User
Longtime User

I have not tested your code.

I will do it later.

Thank you all very much, especially LucaMs

He left you a video of how the test program was working.

 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…