Titanium Community Questions & Answer Archive

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

Avoiding stale data with multi-tasking

Looking for some expert advice on how to handle the situation where a user is using my app and switches focus away via multi taking and then comes back to it maybe a day later. The main tab of my app is pulling the latest news from our cms. As it stands if a user switches back to my app via multi tasking after sometime away they still see the data since they last restarted the app or clicked on the refresh button I have put in the nav bar.

I want to make things as user friendly as possible and avoid the user viewing stale data as much as possible. Reading through other posts here there is the option to disable multi tasking but that would seem to be a negative approach I would like to avoid. Another approach would seem to be to use setInterval but I don't understand how that would operate in an app with multiple tabs (news, events, directory etc).

Any suggestions on the best approach?

— asked December 6th 2010 by Martin Reeves
  • mobile-iphone
  • multi-task
  • multitasking
  • Thanks for the suggestion Aaron. 'resume' seems to fire twice for me that is strange, plus using 'resume' would potentially mean updating more often than necessary. I think I am going to try and in each tab save the time of the last data load and use setInterval to periodically check if the data is older than x minutes as refresh if it is.

    As I understand from reading further posts just using setInterval to refresh every x minutes wouldn't be a good approach as the setInterval timer pauses when the application pauses.

    Any other suggestions?

    — commented December 7th 2010 by Martin Reeves
  • i would suggest that you use a combination of resume and saving a snapshot at a particular time. So upon resume you look to see if a certain amount of time has elapsed or not, if so.. get the data.

    — commented December 7th 2010 by Aaron Saunders

1 Answer

  • listen for the following events… that should get you started

    Titanium.App.addEventListener('pause', function(e) {
    Titanium.App.addEventListener('resume', function(e) {
    — answered December 6th 2010 by Aaron Saunders
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.