Save Settings revisited

Pops

Member
Licensed User
Longtime User
I have a button background that can be changed in the app.
It is also possible to change a label text in the app.
I want whatever label text and button background image that exist when the app closes to still be there when the app is reopened. Is this possible with State Manager, or do I need to save settings/files to a database?
Thanks for any help y'all can give me.
 

Pops

Member
Licensed User
Longtime User
I'm sorry, and not asking for free ride, but I can't seem to wrap my mind around this. I've rewritten my app from App Inventor almost completely with b4a, with this exception:
When the app restarts I need button1.background, button1.text, & label.1 text restored. I've poured over the tutorials on map and statemanager until my eyes glaze over. Any help is highly appreciated!
 
Upvote 0

Pops

Member
Licensed User
Longtime User
I added code to the StateManager module for my button background and label text. It works perfectly for changing orientation and backing out of app. When system kills the app, however, only the label text is restored. Observing in debug mode, the original button background images are loaded, then the button disappears. This happens at: "button1 = data(0)"
What am I missing, other than the fact that I don't know how to save and restore the button background?
The button background is a contact photo and the label text is the contact name.
 
Upvote 0

Pops

Member
Licensed User
Longtime User
I'll post the revision when I get home. This is basically what I did:
On the StateManager module, I used the "edittext" lines as a reference and put "label1 as Label", etc. I did the same with "button". As I mentioned, this works great for orientation change and using the back button to leave the app. When the app is killed the label info is restored, but the contact photo isn't, which means I didn't save it properly. The button, although invisible, are still there and fully functional.
 
Upvote 0

Pops

Member
Licensed User
Longtime User
Here is the revised StateManager file:
This is NOT the latest StateManager that Erel uploaded recently.
 

Attachments

  • StateManager.zip
    1.9 KB · Views: 239
Last edited:
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
You cannot save Drawable objects like that.
Only primitives, custom types and objects that implement the Serializable interface can be saved with RandomAccessFile.WriteObject.

You can save the image file and then load the file when the state is restored.
You can use the Tag property to save the file name when you set the background.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…