B4J Question B4X Pages - How to hide the main page?

tseyfarth

Member
Licensed User
Longtime User
Hello all,

Normally the main page starts first, from there others can follow. I would like to continue having the mainpage be the page that the users are active with 95% of the time. However, before the mainpage is shown, how can I hide (make Invisible) then show it (Make visible) once the user successfully logs in OR, launch the another page first, then the mainpage following. Or must the mainpage be created and shown from the start??

In the mainpage code, I have tried using where appropriate ( B4XPage_Created)
B4X:
Root.Visible = False

And also this in the sub
B4X:
Root.Visible = True

B4X:
Private Sub lb_sing_up_Click
    Root.Visible = False
    B4XPages.ShowPage("page_sign_up")
End Sub

I also tried this code to launch another page first, but after that page is closed, the whole app closes
B4X:
Public Sub Initialize
    B4XPages.GetManager.TransitionAnimationDuration = 0
    Dim p2 As page_sign_up  'Page2
    p2.Initialize
    B4XPages.AddPage("Page 2", p2)
End Sub

But this leaves a white blank form up behind the launched login page. And when the login is complete, it closes the login page, but I only get the blank white page. I do not want the white page showing at all.

What I really need is to understand and see sample code that shows best practices/proper way of doing this. This may not even be the correct/best practices order of operations, so if it is not, please advise.

The intent is to create a B4A and a B4i app, but am starting with B4J B4xPages.

Thank you,
Tim
 
Last edited:

William Lancee

Well-Known Member
Licensed User
Longtime User
This code n B4XMainPage will show "sp" at the start and then when "sp" closes will show B4XMainPage

B4X:
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    Dim sp As startPage
    B4XPages.AddPageAndCreate("sp", sp)
    Sleep(0)
    B4XPages.ShowPage("sp")
End Sub

If "sp" is a login screen, you can prevent closing if the info is incorrect.
B4X:
'In startPage
Private Sub B4Xpage_CloseRequest As ResumableSub
    Dim invalid As Boolean = True  'or false
    If invalid Then Return False Else Return True
End Sub
 
Upvote 0

William Lancee

Well-Known Member
Licensed User
Longtime User
Alternatively, since pages are put on the to-be-shown stack in order of registry, anything in initialize of B4XMainPage is shown firsts.
When finished with "sp", just put MainPage on the stack and close "sp". Since MainPage is the only one on the stack, it will be shown.
Both approaches will work.

B4X:
Public Sub Initialize
'    B4XPages.GetManager.LogEvents = True
    Dim sp As startPage
    sp.Initialize
    B4XPages.AddPageAndCreate("sp", sp)
End Sub

'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
End Sub

B4X:
Private Sub B4Xpage_CloseRequest As ResumableSub
    Dim valid As Boolean = True
    If valid = False Then Return False
    B4XPages.ShowPage("MainPage")
    Return True
End Sub
 
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
see:
 

Attachments

  • Project.zip
    17.9 KB · Views: 60
Upvote 0
Top