|
Save Current State
By default, when you exit and then re-enter a LiveCode created mobile app no state is saved and your application does not resume from where it left off. This lesson will explain how to create a simple app, save the state of an app to a text file when the app closes and when re-opened, have this state re-applied. Create a Stack with Two CardsCreate a new stack with two cards. Card one named "one" and Card two names "two". I have set the size of this stack to 320 x 480 Create some navigation buttons so you can go to and from each card (go next card, go previous card) Now, create some graphics on each card so that when you navigate, you can tell you are on a new card Create a file that saves the state on shutdownWe will want to create/add to this file when a shutDown request is triggered. This is possible is we use the shutDown message The following is added to the stack script- on shutdown
Load this state from the text fileNow that we have saved the state, we will want to load it when the stack is opened. We can do this with the openStack message- Again, on the stack script, add the following on openStack Deploy to device/simNow when you deploy to a device/sim, exit the app and then re-open the last card that you navigated to will be the one show. Although this is a very basic example, the same principles can be applied to content within an application as well (e.g. text fields, button states, control positions etc)
| Tweet
|