How to trap startup and shutdown events in Titanium Mobile
I can't quite figure out how to trap the app startup and shutdown events. I have a tabGroup with 5 tabs in it, and I've tried trapping the following events:
tabGroup.addEventListener('click',function(e) {
Ti.API.info("tabGroup click");
});
tabGroup.addEventListener('open',function(e) {
Ti.API.info("tabGroup open");
});
tabGroup.addEventListener('close',function(e) {
Ti.API.info("tabGroup close");
});
win1.addEventListener('open',function() {
Ti.API.info("win1 open");
});
win1.addEventListener('close',function() {
Ti.API.info("win1 close");
});
The only one that fires is win1 close.
How do I trap startup and shutdown so I can save and restore the application state?
6 Answers
-
Here are some useful application events that you can listen to against
Titanium.App
:- pause: fired when the phone is interrupted (as in an incoming phone call)
- resume: fired when the phone resumes after an interruption. note, you will only get this event if the app is restarted from a pause
- close: fired when the app is shutting down to allow you to save state etc.
For startup, just do something in your app.js since that's
startup
. -
This doesn't appear to fire, at least not in the iPhone simulator:
Ti.App.addEventListener('close',function() { Ti.API.info("save active tab: " + tabGroup.activeTab); Ti.App.Properties.setInt('activeTab',tabGroup.activeTab); });
-
Nice… this is very helpful…
Did I miss this in the online docs, or has this part of the documentation just not been ported over yet?
-
It seems something changed on OS4, I can't get the startup events just adding on app.js
It seems to be something about the new Multi-task feature, so now I can't figure out a way to use the getArguments() to retrieve data from Safari when using Custom URL Schemas.
The 'resume' event works, but I can't retrieve the data with getArguments().
-
I wanted to do a follow up on the status of the startup and the shut down events. I want to do some general housekeeping events on startup, like downloading a config file from the internet to refresh some content. Perhaps even download some pictures. So I am looking for a good spot to have some directory synch logic. Perhaps a manifeast file that compares file dates, and uploads the newest files? could I get some heads up on that. It also needs to run on iPhone and Android.
-
I have a similar question that I already asked here… http://developer.appcelerator.com/question/68121/on-startup-if-i-wanted-to-dl-some-config-data
sorry about the double post.
This question is 7 months old… are there any updates I should know about?