Very simple example got me more confused. I thought I started getting a little handle on this. Why isn't Page2 displayed after B4XMainPage is loaded.:
B4X:
'Code in B4XMainPage
Sub Class_Globals
Private Root As B4XView
Private xui As XUI
Private P2 As Page2
End Sub
Public Sub Initialize
P2.Initialize
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") 'has one button
B4XPages.AddPage("Page2",P2)
B4XPages.ShowPage("Page2")
End Sub
B4X:
'Page2 code:
Sub Class_Globals
Private Root As B4XView 'ignore
Private xui As XUI 'ignore
Public Label1 As B4XView
End Sub
Public Sub Initialize As Object
Return Me
End Sub
Private Sub B4XPage_Created (Root1 As B4XView)
Root = Root1
Root.LoadLayout("2") 'has a label only
End Sub
To explain it better: I want Page2 to be the one visible when the app runs, not B4XMainPage.
Hi: I'm starting to play with B4XPages, just adapting this example It has a login page an then 2 others. What I want to do is to save the logged user (i.e. in KVS) and, from then on, once you start the app check if the user is already logged, then go to the next page instead of B4XMainPage...
www.b4x.com
I'm "adapting" the B4XDrawer example to do this, but I'm getting all kind of errors. Stay tuned¡¡ :-D
I have followed your thread . But mine is much simpler and still could not figure it out. I have been using B4XPages for a while, but in the past I always get the main page to be the starting point. This is a different case where I want Page2 to be shown, not the main page and still be able to go bsck to mainpage.
Your code shows Page2, but there is no way to go back to mainpage.
I have followed your thread . But mine is much simpler and still could not figure it out. I have been using B4XPages for a while, but in the past I always get the main page to be the starting point. This is a different case where I want Page2 to be shown, not the main page and still be able to go bsck to mainpage.
Your code works Jose. The one thing that baffles me is this line: B4XPages.AddPage("Main", Me) in the below sub of B4XMainPage:
B4X:
Public Sub Initialize
B4XPages.GetManager.LogEvents = True
Dim Page_2 As Page2
Page_2.Initialize
B4XPages.AddPage("Main", Me) 'why is this line needed here?
B4XPages.AddPage("Page 2", Page_2)
B4XPages.ShowPage("Page 2")
End Sub
Isn't B4XMainPage added and created in the Sub: Private Sub B4XPage_Created (Root1 As B4XView)
I thought it would be simpler than this.
I'm still a little confused about that, but I've tried and if I don't add the line B4XPages.AddPage("Main", Me), it seems B4XMainPage is not added to the stack
'You need this in the "page2" class or a sleep(0) after loading layout to allow layout loading to complete
'Normally it works because of the MainPage shows first
Private Sub B4XPage_Appear
B4XPages.ClosePage(B4XPages.MainPage)
End Sub
B4X:
Private Sub B4XPage_Created (Root1 As B4XView)
Root = Root1
Root.LoadLayout("MainPage") ' if you don't need this remove it
Dim p2 As page2
p2.Initialize
B4XPages.AddPage("Page 2", p2)
B4XPages.ShowPage("Page 2")
End Sub
Using a stripped down version of Three Pages Example , the sample below does what your trying to achieve.
There is only 2 Events used .. Button_Click to switch between pages .. (No Page_Appear, Initializes etc...)
The main goal was to keep this a simple as possible (minimal code)
As suggested above ... just adding Sleep(0) to your code above solved the issue.
B4X:
'Main Page ...
Private Sub B4XPage_Created (Root1 As B4XView)
Root = Root1
Root.LoadLayout("pageMain")
Sleep(0)
Page2.Initialize
B4XPages.AddPage("Page2", Page2)
B4XPages.ShowPage("Page2")
End Sub
@mangojack is right that his is the simplest solution. However, you can call B4XPages.ShowPage("MainPage") anywhere. It doesn't need to be part of a button.
It works, but it seems this way the B4XPage_Appear event is not fired first time.
Just add to the Page2:
B4X:
Sub Class_Globals
Private Root As B4XView 'ignore
Private xui As XUI 'ignore
Private Label1 As B4XView
End Sub
Sub B4XPage_Appear
Label1.Text = "Page Appear"
End Sub
And you will see when you run the app, the Label1.Text remains "This is Page2". Press home an go back to the app, and it will change.
"B4XPages v1.08 - fixes an issue where the B4XPage_Appear event is not raised when the first page that is shown is not the main page."
I have not read the thread, sorry, but, as in the past the activity Main was immediately shown, now the B4XMainPage is shown. I see no reason to skip this one and open a different one first.
I went crazy with that topic in the first project with B4XPages.
After a lot of reading, searching, questioning, and racking my mind, I decided there was a problem and it wasn't working right. I left it waiting for better times.
It seems that with that new version it is solved, I'm glad, I'll go back to my project.