Android Question How to save views before closing the application...and restore when restart?

javiers

Active Member
Licensed User
Longtime User
Hello,

Is it possible to save the state and the values of imageview and labels contained in a tabhost before closing the application?
The idea is that when restarting the application, these views have the same values and states.
Can you be saving values in a sqlite table?

Thanks for the help.
 

pauleffect

Member
Licensed User
Longtime User
What lucas means is this:

store your sh%^ as variables, File.WriteMap them to a chosen file When you start the app, dim xxx as map, xxx.initialize, xxx= file.readmap(...)
Restore all the stuff you need to the previous state.

I, for example, am using a map right now to store the style of a couple of buttons(button background, icon background, button text, etc) and some user settings. I do it like this:

I did the default map in notepad.
Create a blank file (the default java extension is .properties, but you can use whatever).
# marks a comment. new line means another entry. case sensitive.

button_xxxBG = light_red
button_xxxICON = dark
button_xxxTXT = my awesome text

^this is the key ^this is the value

...


Save the file, put it in file.dirassets.

When the app starts, it checks file.dirinternal for settings.properties. If it's not there, the stock file is copied from the assets to the internal folder, since the assets folder is readonly.

To get the values, dim a map, initialize it, point it to the saved text file and use xxxmap.get("button_xxxBG"). It will return "light_red".
As i said before, case sensitive. If you use it to store boolean values directly, store them like False and True. false and true won't work, from what i've read.


PS: there are better ways to store multiple values to a single key. you can do it like: button_xxx = light_red**dark**my awesome text
Then, in b4a, use string function(or utils, never can separate the two ) to string split the value.

You can also use sqlite, xml, etc. It's really about the scope of your project and the way you want to handle / store/ display that data.

For simple stuff (like the one you mentioned) this is the best IMHO.

Best of luck!
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…