Android Question Save information about parameters for next time opening

German Buchmuller

Member
Licensed User
Longtime User
Hi, I want to make the app to save some information about for example the Background color so that next time the user opens the app, its background color is the same as the one picked before. This can be also used for other things such as Internal Registration of Users with Passwords. Can Anybody of you help me with this? Thanks to All
 

Roger Daley

Well-Known Member
Licensed User
Longtime User
You can also use Textwriter and Textreader in Activity Pause and Acivity Resume respectively.
The code below writes the "Text" of a label and an Array to a text file and on Resume reads it back in.
I have used Statemanager and this method both work.

Regards Roger


B4X:
'Create text file and write Label text and "Recording" Array to Text file.
'Terminate when "EndPlay" is written
    Private PFunction As TextWriter
    Private WriteLine1 As String

    PFunction.Initialize(File.OpenOutput(File.DirRootExternal & "/Download/", Filename1, False))
    WriteLine1 = LabelText   
    PFunction.WriteLine(WriteLine1)                                        'Saves the text of the Label shown on the Calc.   
'Save 5 entries for Result Names ---    Results(FNum,Results_Flag,0)   
    For i = 0 To 4
        WriteLine1 = Results(FNum,i,0)
        PFunction.WriteLine(WriteLine1)   
    Next

    PFunction.Close


B4X:
  PFunction.Initialize(File.OpenInput(File.DirRootExternal & "/Download/", Filename1))
    FunctionLabel = PFunction.ReadLine            'Reads Function key label from file
    PasteFLabel                                    'Write FunctionLabel to function key label .

'Read 5 entries for Result Names ---    Results(FNum,Results_Flag,0)   
    For i = 0 To 4
        Riedlyne  = PFunction.ReadLine
        Results(FNum,i,0) = Riedlyne
    Next

    PFunction.Close
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
You can also use Textwriter and Textreader in Activity Pause and Acivity Resume respectively.
I don't recommend using TextWriter and TextReader unless you must.

If you want to write a text file with several lines then use File.WriteList / ReadList.

For settings it is usually better to use a Map with File.WriteMap / ReadMap.
 
Upvote 0

German Buchmuller

Member
Licensed User
Longtime User
After trying all, I saw that the way I needed was with a txt file. Now, how can I add a line to a txt file without removing the previous? What I mean is this:

text.txt has written on it : hello
Now I want to add below "hello" the word bye

example: hello
bye
I dont know if you understand me. Hope you can
Sorry for being asking for so many things, I am startin with all this and I get Facinated
 
Upvote 0

mangojack

Expert
Licensed User
Longtime User
Last edited:
Upvote 0

German Buchmuller

Member
Licensed User
Longtime User
Well, I tried what you told me but I couldnt do What I wanted. Look, I want to make a registration for users. All users are saved on a txt file. What I want is when you click the login button, to chech in that txt file if the username and password match.

For example:
txt file is like this:
john
1234
pete
5522
paul
3124

Then it will see if any of the words in the txt file match what the user has intruduced at the login screen.
Note that the name would be the username and the number would be the password. Can you help me with this? I will apreciate it SO Much. Thanks anyways. I love this community!
 
Upvote 0

Roger Daley

Well-Known Member
Licensed User
Longtime User

Hi,

The following code is not exactly a match to your requirements but is close. It reads the text file and checks for a match, if a match is found it takes action.
I hope this helps.

Regards Roger

PS This link may help.
https://www.b4x.com/android/help/collections.htmlhttps://www.b4x.com/android/help/collections.html

B4X:
'Check files in FileListing1, if valid add to FileListing2
        FileListing2.Clear 
        For i = 0 To FileListing1.Size-1
            Filename2 = FileListing1.Get(i)
            PFunction.Initialize(File.OpenInput(File.DirRootExternal & "/Download/", Filename2))
            For j = 0 To 99
                Riedlyne  = PFunction.ReadLine
                If Riedlyne = Null Then Exit
                If Riedlyne = "EndPlay"  Then
                    FileListing2.Add(Filename2)
                    Exit
                End If
            Next
            PFunction.Close
        Next
        ImportFileSelect                        'Returns Filename1
        Return                                    'Ignore
    End If
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…