In this chapter, we will cover:
This chapter describes the processes of two fundamentally important, yet deceptively simple, parts of the Titanium framework. In this chapter, we'll explain how to go about creating and reading app properties so that you can store data that is accessible from any part of your application. This is similar to how session data or cookies would work if you were building a web-based app.
We'll also go into further detail on events, including a selection of those fired by the various components in Titanium, and custom events that you can define yourself.
Application properties are used for storing data in key/value pairs. These properties can persist between your app's windows, and even beyond single application sessions, much like a website cookie. You can use any combination of upper case or lower case letters and numbers in a property name, but you should mix them with care as JavaScript is case-sensitive. In this regard, Myname
, myname
, and MYNAME
would be three very different properties!
Application properties should be used when one or more of the following points are true:
For example, storing a string/string key pair of data_url
and "http://mywebsite.com/data.xml" would be a valid way to use app properties. This URL could be re-used throughout all of your application screens/windows and is related to your application, rather than your data.
If your data is complex and needs to be joined, ordered, or queried when retrieving it, then you are better off using a local database built with SQLite. If your data is a file or large blob object, (for example, an image) then this is better stored on the filesystem, in the manner described in our previous recipe.
There are currently five distinct types of objects that can be stored in the app properties module. These include:
In the following recipe, we will create a number of app properties and then read them back, printing them out to the console as we do so.
18.216.151.164