Android Question Configuration File Storing App Settings

asmondien

Member
Licensed User
Longtime User
Hi All,

Hope you can help -

I'm trying to use a configuration file to store app settings like button colour, enabled, disabled, panel colour, text size and text colour. I have this working with the local module.

The next stage was to pull this from API; I have HTTP job to download the settings and store them in the settings.txt. This is also working OK.

So, now I'm trying to assign the value to change the panel colour and I'm getting app crash.

Tracking this down, I believe it's because the values stored in SQL server are in VARCHAR - so, I have it as a string. (I think)

When I use this - I get an app crash
B4X:
pnl_line.Color = kvs.Get(pnl_line)

Could someone point me in the right direction, how to store the value as an object, so when I pull the value via KVS it doesn't crash the app?

I'm presuming it won't be simple as declaring var as an object and using that.

Thanks
 

agraham

Expert
Licensed User
Longtime User
What is the actual error? Color in B4A is an Int so as long as kvs returns a string that contains a valid Integer value it should just work.

Also kvs.Get(pnl_line) looks suspect. You are using what I assume is a Panel object as the key which won't work when you want to restore the value as it won't be the same object the next time round. You should use a string.
 
Upvote 0

asmondien

Member
Licensed User
Longtime User
What is the actual error? Color in B4A is an Int so as long as kvs returns a string that contains a valid Integer value it should just work.

Also kvs.Get(pnl_line) looks suspect. You are using what I assume is a Panel object as the key which won't work when you want to restore the value as it won't be the same object the next time round. You should use a string.
Sorry for the late response -

The error I get:
Error::
Error occurred on line: 28 (KeyValueStore)
java.lang.NumberFormatException: Invalid double: "null"

Within the SQL, I store the value as "Colors. RGB(0,0,0)" which is stored as a string - I believe it can't convert to object to read it as "Colours.xxxxx")

Hope that makes sense.

Thanks
 
Upvote 0

asmondien

Member
Licensed User
Longtime User
That won't work, you can't easily evaluate that at run time. Store it as the Int returned from Colors. RGB(0,0,0) or as a string that converts to an int like "-1".
Sorry, not sure I'm following your thoughts here -

As this doesn't work, I won't be able to store the Colors. RGB(0,0,0) in SQL as string or int - so do you mean this be to split it into 3 values?

Kvs:
pnl_line.color = Colors.RGB(kvs.get(txt_colour_r),kvs.get(txt_colour_g),kvs.get(txt_colour_b))

Thanks
 
Upvote 0

udg

Expert
Licensed User
Longtime User
Another option is to store the color as string (its 8chars Hex representation: Transparency-R-G-B)
Then reading it back and assigning it to an integer variable, counting on the automatic casting from a string representing a number
Afterall, seeing the string FFFFFF00 is clearer than reading -256 to understand it's the Yellow color

BTW, the Color Picker shows you that same FFFFFF00 hex representation which makes it trivial managing colors.
 
Upvote 0
Top