Titanium Community Questions & Answer Archive

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

Using HTTPClient with setInterval and handling pause resume events

I'm using setInterval() to make an XML HTTP Request with Titanium.Network.HTTPClient every 60 seconds. This works fine, but when the handset (iPhone) goes idle after 30 seconds or so of inactivity and locks, when I unlock it and return to the app, the XHR isn't working correctly. It appears to get stuck in a request and never completes (returns).

I tried adding event listeners on the pause and resume events to clearInterval() on pause and setInterval() on resume but this doesn't seem to be working either.

Has anyone else experienced this issue? If so, have you found a solution?

— asked December 1st 2010 by Slim McKinsley
  • httpclient
  • pause
  • resume
  • setinterval

1 Answer

  • my suggestion is that you ensure you shut down any active request when the device locks up, and then make sure you clean up and restart your requests appropriately when the device becomes active again.

    I apologize if you are already doing these things, but since there is no code posted, I am making some assumptions.

    — answered December 1st 2010 by Aaron Saunders
    • Is there an event listener for when the device locks? The pause and resume event listeners do not trigger on device lock, only when a multi-tasking app is sent to the background (home) and then later resumed.

      — commented December 2nd 2010 by Slim McKinsley
    • I've found the hard way that a non-documented event "resumed" is fired when you unlock your device. It seems to do what the "resume" does but also work for unlock. I don't know if there are any "drawbacks" for using it. Let me know if you find anything.

      — commented April 13th 2011 by Vassilis Papakonstantinou
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.