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.
I've tried three different ways, each one with its drawbacks.
First of all, I save the login in KVS
First way
This way (I think this is the right one), when you open the app, you see (even in Release Mode) how everything happens, in the Title bar: "BXAExample -> MainPage-> Page 2"
The effect here is minor because of the low frame rate.
Second way
This way, when you've saved the user in KVS, if you start the app again, it get stucked in MainPage until you touch in some place:
Third way:
Problem: Obviously, if close the app and open it again, the layout is reloaded over the first one when B4XPage_Appear
And, as the B4XTutorial says:
4. B4XPage_Created This is the place to load the layout.
And:
Attached the project with the second option.
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.
I've tried three different ways, each one with its drawbacks.
First of all, I save the login in KVS
B4X:
Sub btnLogin_Click
KVS.Put("user", txtUser.Text.Trim)
B4XPages.ShowPageAndRemovePreviousPages("Page 2")
End Sub
First way
B4X:
Private Sub B4XPage_Created (Root1 As B4XView)
B4XPages.GetManager.LogEvents = True
Root = Root1
KVS.Initialize(File.DirInternal,"kvs")
Page2.Initialize
B4XPages.AddPage("Page 2", Page2)
Page3.Initialize
B4XPages.AddPage("Page 3", Page3)
Root.LoadLayout("Login")
End Sub
Sub B4XPage_Appear
If KVS.ContainsKey("user") Then
B4XPages.ShowPageAndRemovePreviousPages("Page 2")
End If
End Sub
The effect here is minor because of the low frame rate.
Second way
B4X:
Private Sub B4XPage_Created (Root1 As B4XView)
B4XPages.GetManager.LogEvents = True
Root = Root1
KVS.Initialize(File.DirInternal,"kvs")
Page2.Initialize
B4XPages.AddPage("Page 2", Page2)
Page3.Initialize
B4XPages.AddPage("Page 3", Page3)
If KVS.ContainsKey("user") Then
B4XPages.ShowPageAndRemovePreviousPages("Page 2")
Else
Root.LoadLayout("Login")
End If
End Sub
Third way:
B4X:
Sub B4XPage_Appear
If KVS.ContainsKey("user") Then
B4XPages.ShowPageAndRemovePreviousPages("Page 2")
else
Root.LoadLayout("Login")
End If
End Sub
And, as the B4XTutorial says:
4. B4XPage_Created This is the place to load the layout.
And:
Tip: don't treat B4XPages as activities. In most cases you don't need to do anything in the Appear and Disappear events.
Attached the project with the second option.