views:

40

answers:

2

Hello,

Nearly done my first titanium developer app however, the biggest issue (and lack of documentation of) is the ability to execute a function in the background.

I have a function that basically just queries an external json file and then loops through it inserting about 150 records in the database. This completely hangs the app until it's done.

I've tried a jquery async loop plugin and it works though the rest of the app is still very slow / responsive to any commands.

It has to be possible to execute a function in a background thread or something while the rest of the app is completely accessible.

Anyone know how to do this?

A: 

just put your code in a setTimeout:

setTimeout(function (){
  /* your code */
},0);

The behavior is like a thread.

madeinstefano
unfortunately this has no effect in appcelerator, it still hangs up the app while the loop is running.
Joe
A: 

One solution here indicates the specific functionality will be available in a later release

http://developer.appcelerator.com/question/68231/background-thread--timer-thread--service-thread

Another solution is to create a event and fire it off since windows/views execute on a separate thread, Scroll down to the Events Section on this page

   // fire  the event for the task
   Ti.App.fireEvent("doLongTask");


   Ti.App.addEventListener("doLongTask", function () {
                        // doing long task...
                       });
Aaron Saunders