Android Question How to save settings?

trueboss323

Active Member
Licensed User
How can I save my settings inside my app. In VB.NET you use
B4X:
My.Settings
and you can change what type of value (String, Boolean, Integer, etc)
What is the easiest way I can do that in B4A ?
 

trueboss323

Active Member
Licensed User
Hi,
I looked at the library. Could you please provide an example?
Say that I want to save a simple textbox like My.Settings.text = TextBox1.Text
and then load it like: TextBox1.Text = My.Settings.text
Whats the best way i can do that?
 

trueboss323

Active Member
Licensed User
StateManager is very easy to use.
Thanks. I'm still trying to figure out how I could save booleans like checkboxes, I can't seem to find the proper code for saving, and loading them.
Could you provide some help please ?
 

sorex

Expert
Licensed User
I never worked with checkboxes but I guess it will be something like

B4X:
'load or set first time defaults
StateManager.loadStateFile
chkOption1.checked=StateManager.GetSetting2("option1",0)

'saving
StateManager.SetSetting("option1",chkOption1.checked)
StateManager.SaveSettings
 

trueboss323

Active Member
Licensed User
I never worked with checkboxes but I guess it will be something like

B4X:
'load or set first time defaults
StateManager.loadStateFile
chkOption1.checked=StateManager.GetSetting2("option1",0)

'saving
StateManager.SetSetting("option1",chkOption1.checked)
StateManager.SaveSettings
I have tried your code and unfortunately that didn't work for me.
 

sorex

Expert
Licensed User
worst case you can solve it with if/then's

B4X:
'load or set first time defaults
StateManager.loadStateFile
if StateManager.GetSetting2("option1",0)=0 then
chkOption1.checked=false
else
chkOption1.checked=true
end if

'saving
if chkOption1.checked=false then
StateManager.SetSetting("option1",0)
else
StateManager.SetSetting("option1",1)
end if
StateManager.SaveSettings
 

trueboss323

Active Member
Licensed User
Thank you! That one worked. And do you also know how I can do the same with text and labels? Since I'm not sure if StateManager.SetSetting("text1",1) would work with Strings.
 

sorex

Expert
Licensed User
the first is the paraeter name, the second the value so you could use

B4X:
StateManager.SetSetting("text1",editText1.text)
 
Top