Detecting when app/script is shutdown

Hi all,

I’ve decided to give Codea a try and found an issue I can’t resolve. Simply put, does Codea notify the running script that the user has pressed the home button or that the app has transitioned to the background? This is assuming the script was exported to xCode and compiled to a native app. Is there an equivalent to ‘applicationWillResignActive’ or ‘applicationDidEnterBackground’? I’m an experienced iOS developer and would rather use Codea than Objective-C for quick app ideas.

I ask because in my app I would like to save the current data (tables) so the user doesn’t have to re-create the data each time they run the app (assuming I’ve exported the app to xCode). I’ve looked at serializing the table structures after each change is made, but that’s a lot of overhead which I’d rather push to a ‘shutdown()’ method if possible.

Thanks for any suggestions!

-Brian

Im not as expirienced as many other users, and this is probably not the most efficient way if it does work, just a quick thought in my head, but you could either
a) save the table as savelocaldata() or
B) upload it to a storage site using an http.request with parameter table

And i cant answer the running script thing, I’m more of a Python and Batch file guy

How big is this table that you wish to save? I can’t imagine serializing it would use up that much overhead. If its just one layer, loop it into a string and write a simple parser to read it back out. Save it in local data. If its a little more complex look into Json which encodes it into JavaScript object notation, save it then decode it.

CodeaNoob, thanks for the reply! I’m currently saving the table to local data on every change. As for the http.request(), I can’t assume that the users will have internet access so that’s why I was hoping for a more elegant solution.

Briarfox, thanks for replying too! The table contains about 200-300 data elements that are generated by the user and periodically modified by the user. Serializing that much data every time a single change is made just doesn’t make sense to me. I like the JSON idea, which would work, but the app is used ‘out in the field’ and I can’t assume the user will have internet access.

For now, I’m going to try and batch some of the changes and then periodically serialize the full table. Hopefully Codea will gain support for SQLite DB access (which would be sweet).

I asked about this before there isn’t one yet as far as I know, and I dont know if simeon plans on adding one

You can extend the exported app to do Codea functions when the app goes into the background. I,m not experienced with Objective-C enough to pseudo code it, but I have seen examples of calling Lua code from objective-c on this forum.

Thanks for your input Luatee & aciolino. I decided to write a quick class that batches the data changes and then every 5 changes, write the data back out. I’ve looked at the Lua bridge stuff and for now don’t have the time to add a callback.