Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

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?

— asked March 21st 2010 by Mark Burggraf
  • events
  • mobile
  • shutdown
  • startup
  • tabgroup
0 Comments

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.

    — answered March 21st 2010 by Jeff Haynie
    permalink
    0 Comments
  • 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);
    });
    
    — answered March 21st 2010 by Mark Burggraf
    permalink
    0 Comments
  • 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?

    — answered March 21st 2010 by Mark Burggraf
    permalink
    0 Comments
  • 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().

    — answered June 2nd 2010 by Antonio Silveira
    permalink
    0 Comments
  • 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.

    — answered June 9th 2010 by vincent youmans
    permalink
    0 Comments
  • 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?

    — answered October 7th 2010 by vincent youmans
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.