Titanium Window handling

This goes for Android + Titanium 1.4.2 SDK (and possibly also for iPhone)

When creating an app with only one user window, you sometimes have to create two windows. Why? You may need to accomplish some tasks when the app is closed by the user. For example, let’s say you are using the accelerometer, when the accelerometer listener is created you have to close it when user closes the app. Or when using GeoLocation with GPS, you don't want the satellite icon to keep on search for location updates, you want it down when user ends the app.

One way to close those listeners is to close them when the window is closed, at the window close event. But when using just one window, when closing the application, in most cases the app is still active in he memory area of the phone, and the app window isn't really closed, so the event listeners mentioned will not be called.

One solution to this problem is to create another window, a "main app window". Kick it open by using a dummy window, for instance the very first window often created in the app.js file. Then, when closing the main app window, the main app window will really be closed and the ending tasks in your close events will be called.

And same goes for the open event… since windows most often still are "open" after user ends the app, there will be no variable initializations for example in the window open event. Using a second “app main window” actually opens a new window, and the open event will be called.

/Peter Marsch