Android Question Restore username in B4XPage

StarinschiAndrei

Active Member
Licensed User
Longtime User
Hi everyone,

Based on Erel's ThreePagesExample , i want to load last user that loged in txtUser. Last username is stored in logindata.dat
B4X:
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    'load the layout to Root
    Root.LoadLayout("Login")
    Page2.Initialize
    B4XPages.AddPage("Page 2", Page2)
    Page3.Initialize
    B4XPages.AddPage("Page 3", Page3)
    If File.Exists(File.DirAssets,"logindata.dat") =True Then
        username=File.GetText(File.DirAssets,"logindata.dat")
    End If
    txtUser.Text=username
End Sub
txtUser is empty
How can i do this
Attached you can find my project
Thank you
 

Attachments

  • B4AProject.zip
    14.4 KB · Views: 11
Solution
In your project from post #1 you have this routine:
B4X:
Sub B4XPage_Appear
    txtUser.Text = ""
End Sub
This means that you set txtUser.Text to an empty string !
Sub B4XPage_Appear is called after B4XPage_Created and every time you show this page again.

StarinschiAndrei

Active Member
Licensed User
Longtime User
The name of the last logged-in user cannot be in a file in Assets; this is a read-only file.
You must create a file in File.DirInternal. Tip: Use KeyValueStore2.
Thank you Luca for your advice , the problem is the the txtUser is empty even if i use a constant

B4X:
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    'load the layout to Root
    Root.LoadLayout("Login")
    Page2.Initialize
    B4XPages.AddPage("Page 2", Page2)
    Page3.Initialize
    B4XPages.AddPage("Page 3", Page3)
    txtUser.Text="UserTest"
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
In your project from post #1 you have this routine:
B4X:
Sub B4XPage_Appear
    txtUser.Text = ""
End Sub
This means that you set txtUser.Text to an empty string !
Sub B4XPage_Appear is called after B4XPage_Created and every time you show this page again.
 
Upvote 1
Solution

StarinschiAndrei

Active Member
Licensed User
Longtime User
In your project from post #1 you have this routine:
B4X:
Sub B4XPage_Appear
    txtUser.Text = ""
End Sub
This means that you set txtUser.Text to an empty string !
Sub B4XPage_Appear is called after B4XPage_Created and every time you show this page again.
Thank you Klaus :rolleyes:,i didn't see it 🙏
 
Upvote 0
Top