iOS Question B4i B4XPage_Background & Back Button

asmondien

Member
Licensed User
Longtime User
Hello,

I'm playing around with the B4XPages, and iOS -

I'm using the native back button on iOS - to go back to previous page, it was simple navigation.

If I press that - I then use to clear input boxes.

B4X:
Private Sub B4XPage_Disappear
  ' Clear my input boxes         
End Sub

However if minimize the app, to leave in the background to get check on email to get verification code and return back to the application it clears the input boxes.

So, I saw there is the B4XPage_Background - which I was hoping somehow to split this;

IF - I press the back button, sure clear the input boxes;
IF - I minimize the app, I dont want the input boxes to clear;

Could some point me to the direction or best practice to somehow do what I desire?

Thank you.
 
Solution
Start by adding in both subs a Log("{subname}"). Do this to see which event fires first as I do not remember. If the Background event fires first then just create a public boolean variable in the page you want (f.e. bSetToBack = False), make it public and set it from the background event to true when the app gets to background. Then:

B4X:
Private Sub B4XPage_Disappear
If bSetToBack = False Then
   'clear textboxes
End if
End Sub

Also in the Appear event set again bSetToBack = False

hatzisn

Expert
Licensed User
Longtime User
Start by adding in both subs a Log("{subname}"). Do this to see which event fires first as I do not remember. If the Background event fires first then just create a public boolean variable in the page you want (f.e. bSetToBack = False), make it public and set it from the background event to true when the app gets to background. Then:

B4X:
Private Sub B4XPage_Disappear
If bSetToBack = False Then
   'clear textboxes
End if
End Sub

Also in the Appear event set again bSetToBack = False
 
Last edited:
Upvote 0
Solution

asmondien

Member
Licensed User
Longtime User
Start by Adding in both subs a Log("{subname}"). Do this to see which event fires first as I do not remember. If the Background event fires first then just create a public boolean variable in the page you want (f.e. bSetToBack = False), make it public and set it from the background event to true when the app gets to background. Then:

B4X:
Private Sub B4XPage_Disappear
If bSetToBack = False Then
   'clear textboxes
End if
End Sub

Also in the Appear event set again bSetToBack = False

Thanks for the response -

When I minimize the app - B4xPage_Disappear triggers first, and then background.

So I used sleep method with and bool; to figure out what's happening and it seems to work.

B4X:
Private Sub B4XPage_Disappear
    Log("B4xPage-Disappear")
    pendingClear = True
    Sleep(200)
    If pendingClear Then
        txt_userName.Text = ""
        txt_password.Text = ""
        txt_code.Text = ""
        foundAccount = False
        but_login.Text = "Find my account"
        txt_password.Visible = False
        txt_code.Visible = False
    End If
End Sub

Private Sub B4XPage_Background
    Log("B4xPage-Background")
    pendingClear = False
End Sub

Private Sub B4XPage_Appear
    pendingClear = False
End Sub


Thank you for the help.
 
Upvote 0
Top