Android Question save program settings

Mostez

Well-Known Member
Licensed User
Longtime User
I want to save program settings(changed by user, then read at program start), i.e baud rate, preferred communication method, calibration factors..etc. what is the best method to do that? An example is highly appreciated.

thanks
 

mcqueccu

Well-Known Member
Licensed User
Longtime User
You can save it in text file or use keyvaluestore2

B4X:
    'To save your data
    Dim m As Map
    m.Initialize
    m.Put("baud_rate", your_baud_rate)
    m.Put("pref_communication", your_pref_comm)
    m.Put("calibration",your_calibration)   
    File.WriteMap(File.DirInternal,"settings.dat",m)
    
    'TO READ THE VALUES TOO   
    Dim myData As Map = File.ReadMap(File.DirInternal,"settings.dat")
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
I don't think he can use keystore because the user wont be able to modify the settings outside of the app because the keystore file is internal, right?

And if the setttings file is to be externally accessible/modifyable, wouldn't there be a problem of the app not being able to read/write to that file due to all the lockdowns that API 29 has on external files/memory?

But if you meant that the user would make the changes to settings from *within* the app, then disregard the above because I initially interpreted the OP as if the user would modify the settings file external to the app, then the app would read in the new settings
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
I don't think he can use keystore because the user wont be able to modify the settings outside of the app because the keystore file is internal, right?
I don't think that the user is expected to change the settings file directly.

(Note that B4XPreferenceDialog is a good tool for settings layouts.)
 
Upvote 0

mcqueccu

Well-Known Member
Licensed User
Longtime User
yes Erel, there will be user activity to change settings from


But the settings files, that will be saved will NOT be changed DIRECTLY by the user, outside of the application. That is what Erel meant
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…