Titanium Community Questions & Answer Archive

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

execute events / functions in a background process

I'm having a heck of a time to execute functions in the background. I have one function that queries an external json file and the loops through it and inserts around 150 records into an sqlite database and it literally takes 30 seconds to do and while it's running the app is entirely useless (freezes).

I've tried the jquery async loop plugin and it works though navigating the app while its running is extremely slow / choppy.

Is there no titanium function that allows me to execute a function in the background that doesn't affect the rest of the app?

This is driving me nuts, without this my app is beyond useless :(

— asked October 25th 2010 by Joe Pilon
  • background

2 Answers

  • While Titanium Mobile doesn't have proper backgrounding, there are a couple of things you can try….

    • Create a new window and execute it in that, each window has it's own context so it might not interfere with your current display context. You can let you main UI window know that it's done by an event.

    • Fire an event and have your other item listen for it, being as events are fired asynchronously they provide you with some level of backgrounding.

    — answered December 13th 2010 by Mike Robinson
  • I'm not sure if you are able to do this but what I would recommend is getting a smaller amount of data from the json file.

    Then, paginate the data when displayed (similar to the app store how you scroll down). I would even prefetch the data so the user doesn't notice the loads.

    — answered December 13th 2010 by John Welch
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.