B4J Question B4Xpages issue with B4XPage_Appear

MrKim

Well-Known Member
Licensed User
Longtime User
I am running some code in B4XPage_Appear to make sure the user has provided all of the necessary information before proceeding - only tested in B4J.

B4X:
Private Sub B4XPage_Appear
    If AddOrEditMode = "AddOrEdit-Edit" Then
        Log(B4XPages.MainPage.GroupCmboTxt)
        Dim S As String = B4XPages.MainPage.GroupCmboTxt
        Log(S)
        If S.Length = 0 Then
            Dim sf As Object = xui.MsgboxAsync("No Group selected. You must select a group and user to edit", "Invalid Group")
            Wait For(sf) Msgbox_Result (Result As Int)
            B4XPages.ShowPageAndRemovePreviousPages("MainPage")
            Return
        End If
.
.

.

The problem I am having is if I remove the page with B4XPages.ShowPageAndRemovePreviousPages("MainPage")

Then the sub B4XPage_Appear doesn't run again until I close and reopen the app.

Don't know if this is a bug or if I should be handling this another way.

Thanks for any help.
 

MrKim

Well-Known Member
Licensed User
Longtime User
The issue has to do with how you open it.

this works fine:
B4XPages.ShowPageAndRemovePreviousPages("Page 2")
This doesn't: B4XPages.ShowPage("Page 2")
In the second example if you close the page inside B4XPage_Appear then the event won't happen again.

In the example I posted log in as '1234' and it will close Page 2 inside the B4XPage_Appear event and then the B4XPage_Appear event will not happen again until you close and reopen the program.
 

Attachments

  • B4XPage_AppearIssue.zip
    7.6 KB · Views: 152
Upvote 0

MrKim

Well-Known Member
Licensed User
Longtime User
That's true and it is by design. In B4J all the pages remain visible until they are closed.
I'm sorry, I just don't understand. The description of this event states:
'B4XPage_Appear - Called whenever the page becomes visible.
I am closing that page (page 2). It is no longer visible on my screen. On my taskbar I had TWO Icons. 1 for 'MainPage' and one for 'Page 2' After I close 'Page 2' I have 1 Icon on my taskbar 'MainPage'. 'Page 2' is, to me, not visible. Under those circumstances it would seem to me that when I reopen 'Page 2' the B4XPage_Appear event would fire.

So if what is actually happening is ALL pages must be invisible and then the event fires but only for the page that is being made visible? If that is the case then it is inconsistent.
I open the program - MainPage is visible.
I open page 2 using B4XPages.ShowPage - B4XPage_Appear fires.
I close page 2 using B4XPages.ShowPageAndRemovePreviousPages("MainPage")
MainPage B4XPage_Appear Fires clearing the password
I type in a new password and open page 2 again B4XPage_Appear does NOT fire.
I close page 2 using B4XPages.ShowPageAndRemovePreviousPages("MainPage")
MainPage B4XPage_Appear does NOT fire.

Out of curiosity I then went to the code and changed btnLogin_Click
back to
B4XPages.ShowPageAndRemovePreviousPages("Page 2")
Without closing the program.
I then closed and reopened 'Page 2' several times and B4XPage_Appear never fired again.
So, it appears that if you open a page (at least from MainPage) using ShowPage rather than ShowPageAndRemovePreviousPages the B4XPage_Appear event will stop firing until the program is restarted.
 
Upvote 0

MrKim

Well-Known Member
Licensed User
Longtime User
Again,
For me, This works:
B4X:
Sub btnLogin_Click
    B4XPages.ShowPageAndRemovePreviousPages("Page 2")
End Sub

With this B4XPage_Appear stops firing in both Page 2 and MainPage
B4X:
Sub btnLogin_Click
    B4XPages.ShowPage("Page 2")
End Sub
And I cannot find a way to get them to start again without closing and reopening the program.
And I am using the original Threepages example and changing only ShowPageAndRemovePreviousPages to ShowPage on the MainPage.

I just tested it with B4A and the behavior is not the same!
In B4A I can change to
B4X:
Sub btnLogin_Click
    B4XPages.ShowPage("Page 2")
End Sub
And B4XPage_Appear will continue to fire.
In B4J it does not.
 
Upvote 0

MrKim

Well-Known Member
Licensed User
Longtime User
AHA! You are right! IF I click the X to close it continues to fire
I am clicking btnSignOut on Page 2 and when I do that it stops firing.
That code uses
B4XPages.ShowPageAndRemovePreviousPages("MainPage")

Also, I think the behavior is different in B4A. In B4A as mentioned, The Event continues to fire after using btnSignOut .
But, the behavior of the back arrow (which I am assuming is supposed to be equivalent to the X in B4J) also signs you out. The same as btnSignOut_Click.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
You realize that if you don't call:
B4X:
Sub btnLogin_Click
    B4XPages.ShowPageAndRemovePreviousPages("Page 2")
End Sub
Then both pages are visible. You can move page 2 and you will see the login page behind it. Later when you call ShowPageAndRemovePreviousPages("MainPage"), the main page is already in the stack and is therefore removed.

If you really want to show both pages together then call B4XPages.ClosePage(Me) in btnSignOut_Click.
 
Upvote 0

MrKim

Well-Known Member
Licensed User
Longtime User
AHA!

Now I see it. Checking...
While yo are rooting around in there you might want to look at this as well? It is another issuer
Yes, there are many instances when I might want more than one page displayed. In this particular case if we open 'Page 3' then do as you say with page 2 it will leave 'Page 3' open. also upon testing this it seems ShowPageAndRemovePreviousPages is a bit of a misnomer because if I open page 3, then go back to page 2 and click btnSignOut it closes Page 2 AND 3 even though Page 3 is not a Previous Page.

I want you to know, I REALLY REALLY like what you are doing here. I hope I am not being to much a pain but for the first time I feel like I can develop in all three. So I just really want to understand how it all works.

Thanks again.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
This use case should be covered with v1.05. Try it.
 
Upvote 0

MrKim

Well-Known Member
Licensed User
Longtime User
There is still the issue of different behavior between B4J and B4A. I am not sure if it is supposed to be this way or not.

In B4A there appears to be no way to get back to the MainPage without firing the B4XPage_Appear event. Both the items above, as well as the BACK button on my phone clear the password whereas clicking the X in B4J. Will close Page 2 and take you back to MainPage without firing B4XPage_Appear.

I even tried using B4XPages.ClosePage(Me) and it still fired B4XPage_Appear on the MainPage.
Is this by design because you cannot view two pages at once in B4A? (And I am assuming B4i will be the same?)
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…