Properties & the Home Button
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
- VIP Livecode Opensource Backer
- Posts: 219
- Joined: Mon Dec 05, 2011 5:35 pm
Properties & the Home Button
I am confused about property data persistence.
I thought that property data was like a database: immediate save and persistent. I am getting different behavior. Here is the the situation.
I set a property value (user preference) on the card. Change it from A to B to C. The last preference in the property is C (confirmed).
Then when the Home button on the iPhone simulator is pressed we leave the app. Then restart the app and Voila (sarcasm!). The property is set to A (the value when it first loaded in the simulator) and not C (the expected value) the last value just before the home button was pressed.
I have been fighting with this for hours. Any insight as to why the property value is not persisting after the app is suspended?
Since we are on the topic. What is the standard practice for handling interruptions like a phone call, home button presses, etc. I thought property values were persistent.
coffee16
I thought that property data was like a database: immediate save and persistent. I am getting different behavior. Here is the the situation.
I set a property value (user preference) on the card. Change it from A to B to C. The last preference in the property is C (confirmed).
Then when the Home button on the iPhone simulator is pressed we leave the app. Then restart the app and Voila (sarcasm!). The property is set to A (the value when it first loaded in the simulator) and not C (the expected value) the last value just before the home button was pressed.
I have been fighting with this for hours. Any insight as to why the property value is not persisting after the app is suspended?
Since we are on the topic. What is the standard practice for handling interruptions like a phone call, home button presses, etc. I thought property values were persistent.
coffee16
Re: Properties & the Home Button
Hi! There is not any persistence: when you leave the app, all came back to the state of the creation of the standalone. To restore you can save the needed data in an external file (e.g. Text file, or stack file) and set again via code.
-
- VIP Livecode Opensource Backer
- Posts: 219
- Joined: Mon Dec 05, 2011 5:35 pm
Re: Properties & the Home Button
Thanks Mag
For some reason I thought that properties persisted. But i guess it makes sense that they don't. Thanks for that. I will either save to a user profile file or a database.
Follow up: as far as I can tell the the closeCard handler is not called when there is an interruption like a home button press. If I'm wrong that would be great, but if true, then how can you handle a quick app state save so that you can return to the same place as the user left off? Is there a handler for interruptions?
Coffee16
For some reason I thought that properties persisted. But i guess it makes sense that they don't. Thanks for that. I will either save to a user profile file or a database.
Follow up: as far as I can tell the the closeCard handler is not called when there is an interruption like a home button press. If I'm wrong that would be great, but if true, then how can you handle a quick app state save so that you can return to the same place as the user left off? Is there a handler for interruptions?
Coffee16
Re: Properties & the Home Button
Hi Coffee,
try with the "on shutdown" ... iOS should give you the time to quickly save your environment before closing
Guglielmo
try with the "on shutdown" ... iOS should give you the time to quickly save your environment before closing

Code: Select all
on shutdown
...
do what you have to do
...
pass shutdown
end shutdown
Re: Properties & the Home Button
Hi Coffee,Coffee1633 wrote:Thanks Mag
For some reason I thought that properties persisted. But i guess it makes sense that they don't. Thanks for that. I will either save to a user profile file or a database.
Follow up: as far as I can tell the the closeCard handler is not called when there is an interruption like a home button press. If I'm wrong that would be great, but if true, then how can you handle a quick app state save so that you can return to the same place as the user left off? Is there a handler for interruptions?
Coffee16
in desktop there is not problem to use closeCard, closeStack, shutdownRequest and so on but in mobile things are a bit different. In iOS the system gives you about 5 seconds before to remove from memory your app after user presses home button, in Android you don't know when user leave your app (and even less when it is closed).
I suggest you to save in an external file the most part of the info just as soon as it change. For example when the user chose Audio ON or OFF in your app's settings card, save that data as soon as user leaves Setting card (if under iOS), or shortly after user clicks on the ON/OFF button (in Android and iOS too).
I experimented different approaches and this is the one I found fits better the needs of mobile environment.
-
- VIP Livecode Opensource Backer
- Posts: 219
- Joined: Mon Dec 05, 2011 5:35 pm
Re: Properties & the Home Button
Thank you Mag
The persistence/ user settings options in LC are starting to crystallize. I think I will do an immediate save to file of user prefs as soon as the user leaves the settings pop up menu.
Aside:
I am finding that there is a lot more to creating apps than just writing code. Data persistence, defensive programming, writing clear variable and handler names, organizing code so you can understand it months later and on and on is all something I wasn't expecting when LC tricked me (In a good way) into believing that anyone can create an app. There is a lot more to it that just coding. Whew
Thanks again for the clarification.
Coffee16
The persistence/ user settings options in LC are starting to crystallize. I think I will do an immediate save to file of user prefs as soon as the user leaves the settings pop up menu.
Aside:
I am finding that there is a lot more to creating apps than just writing code. Data persistence, defensive programming, writing clear variable and handler names, organizing code so you can understand it months later and on and on is all something I wasn't expecting when LC tricked me (In a good way) into believing that anyone can create an app. There is a lot more to it that just coding. Whew
Thanks again for the clarification.
Coffee16
Re: Properties & the Home Button
LOL.
I fell straight into the same trap. I was storing some values in the custom properties of the stack only to find they were not there later.
I felt they would be persistent because they were properties and not variables. It is sort of implied but definitely not stated anywhere.
It is more of a lack of documentation rather than an documentation error for me.
Time to bring out my trusted external file routines again.
I fell straight into the same trap. I was storing some values in the custom properties of the stack only to find they were not there later.
I felt they would be persistent because they were properties and not variables. It is sort of implied but definitely not stated anywhere.
It is more of a lack of documentation rather than an documentation error for me.
Time to bring out my trusted external file routines again.
-
- Posts: 746
- Joined: Sun Feb 04, 2007 11:01 pm
Re: Properties & the Home Button
Look at it this way. If you opened a word processor and you entered some text and saved the document. Then close the word processor. Later you open the same document and enter more text but this time you just close the application. The next time you open your document, would you expect the text from the later edit to be there? Of course not because you didn't save it. The same thing applies to a LC stack. In iOS the main stack can't be saved anyway. That's why you need to save to an SQLite Db, a separate stack or a text file. Where and when you save depends upon the app and the amount of data being saved. HTH
PS: I case you haven't realized it yet. When writing apps, or any kind of programing, very little happens "automatically". That's not just in LC but JAVA, C and ...
PS: I case you haven't realized it yet. When writing apps, or any kind of programing, very little happens "automatically". That's not just in LC but JAVA, C and ...
Tom
MacBook Pro OS Mojave 10.14
MacBook Pro OS Mojave 10.14
-
- Posts: 379
- Joined: Thu Dec 08, 2011 2:43 am
Re: Properties & the Home Button
Thanks to the wonderful Klaus for his preferences-saving scripts. I've been using them for years.
http://newsletters.livecode.com/october ... etter3.php
http://newsletters.livecode.com/october ... etter3.php
-
- Posts: 14
- Joined: Wed Dec 13, 2006 6:09 am
Re: Properties & the Home Button
I am guessing that the problem I am having is pretty much the same issue: my app allows users to launch their browser to specific URLs. When the Browser opens up in IOS9, there is the Back to the App button that shows up at the very top of their screen (built in and new to iOS9). Clicking on it takes them right back to my app. However, when they get back to my app, they go back to the starting card of my app, not the card they left from. I was not expecting that as I was assuming that my app was still running in the background. So, the behavior is more like launching the app all over again.
Is there a simple solution to this, or should I look at saving the card and state before I launch the browser, then check that state in a preOpenStack script? If the state exists, then I go to that card....etc.
Thanks!
Is there a simple solution to this, or should I look at saving the card and state before I launch the browser, then check that state in a preOpenStack script? If the state exists, then I go to that card....etc.
Thanks!