O'Reilly logo

Appcelerator Titanium: Up and Running by John Anderson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 8. Titanium App Storage

All mobile apps need to store some data to be useful. If there is a file or something else that the user will need more than once or twice, it makes sense to store it locally. This will make it immediately available next time the app is run, and more importantly, if there is no cell service available. Designing an app to work even if there is no cell signal makes it that much more valuable. This is where caching data plays a big part. If the network is available, data can be downloaded, and if not, a cached version can be used. HTML5, for instance, provides a “cache manifest” to address this need. Since Titanium creates native apps, it can’t use the cache manifest, but it’s quite possible to create a download function that maintains a cache of previously downloaded items and uses the cached version if it’s available.

Local File Storage

One way to store data onto a mobile device is to put it in a regular old filesystem file. This is a pretty convenient way to store data, especially text or JSON data. Writing to a file doesn’t require much setup, and both the writing and the reading back are quick and easy. Also, on Android devices, the external storage makes a good place to store files that another app might need to read. This is impossible on iOS devices, though, as there is no external storage. Of course you can still write files to the iOS filesystem, it’s just not on an external SD card and an app can only read the files in its own sandbox storage ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required