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?
 
Upvote 0

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
 
Upvote 0

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.
 
Upvote 0

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
 
Upvote 0

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.
 
Upvote 0

sorex

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

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