Application type: mobile, Titanium SDK version 3.2.3.GA, Platform : iphone, Device: ios simulator 7.1, Host Operating System: OSX 10.9.3
Hello everyone, I am asking question on Q & A for the first time so if miss out on anything, please excuse me.So what i am looking for is an insertion of approximately 3000 entries in database which should be carried out in the backend(another thread) and simultaneously I want do other work on the app.But this seems to a bit unachievable when I click on show animation button and followed by a click on btnRegister.As i looked into the behaviour what i understand is that the moment onload event is fired on success the vwAnimator which is expanding freezes till the insertion in database completes and than it resumes to normal which shouldn't be the case.What i want is the execution of onload event without any affect on the view which is expanding.Now, Whats more interesting is that the network HTTPClient works asynchronously by default on ios as per documentation so i am assuming it executes on different thread and if it does it shouldn't be affecting the view which is expanding. If someone can put more light on this by checking the below test case, it would be really helpful to me. test case:
var window = Ti.UI.createWindow({ width : Ti.UI.FILL, height : Ti.UI.FILL }); var array = []; for (var j = 0; j < 100000; j++) { arr.push({ userid : j, firstname : 'abc', lastname : 'xyz', mobile : 0123456789, city : 'Albion', states : 'NEW YORK', pin : 'abcdef', salary : 8000.32, salaryband : 2, grossSalary : 100010.68, comments : 'In this article, I will discuss self-executing or self-invoking functions of javascript and thei r hidden power with real-world example. We will also see why using setInterval is bad i n some situations and should be avoided. Let’s explore little used but extremely power ful self-invoking functions of javascript.A self-invoking anonymous runs automatically/i immediately when you create it and has no name, hence called anonymous. Here is th e format of self-executing anonymous function:' }); } var db = Ti.Database.install('/maniDB.sqlite', 'myDB'); db.execute('CREATE TABLE IF NOT EXISTS registerTable (uid INTEGER PRIMARY KEY,fname TEXT,lname TEXT,mobile INTEGER,city TEXT,states CHAR, pin INTEGER,salary REAL, salaryband INTEGER,grossSalary REAL,comments CHAR)'); var btnRegister = Ti.UI.createButton({ bottom : '20dp', width : '100dp', height : '100dp', title : 'Register' }); btnRegister.addEventListener('click', function(e) { var xhr = Ti.Network.createHTTPClient(); var parameter = { your web calling parameter}; xhr.onload = function() { db = Ti.Database.install('/maniDB.sqlite', 'myDB'); var i, j = 1, flag = true; db.execute('BEGIN'); for ( i = 0; i <array.length; i++) { db.execute('INSERT INTO registerTable (uid,fname,lname,mobile,city,states,pin,salary,salaryband,grossSalary,comments) VALUES (?,?,?,?,?,?,?,?,?,?,?)', j, item.user[i].firstname, item.user[i].lastname, item.user[i].mobile, item.user[i].city, item.user[i].state, item.user[i].pincode, item.user[i].salary, item.user[i].salaryBand, 100010.10, item.user[i].comment); //incrementing j so tat primary key doesnt duplicates i.e uid j++; } db.execute('COMMIT'); }; xhr.onerror = function() { Ti.API.info(' error ' + this.responseText); }; xhr.setTimeout = 60000; xhr.open("POST", 'your web link here', true); xhr.send(parameter); db.close(); db = null; }); window.add(btnRegister); var vwAnimator = Ti.UI.createView({ height : '30dp', width : 0, top : '60dp', backgroundColor : 'blue' }); window.add(vwAnimator); var expandView = Ti.UI.createButton({ // left : '0dp', top : '300dp', title : 'Show Animation' }); var interval; expandView.addEventListener('click', function(e) { interval = setInterval(function() { // Ti.API.info('vwAnimator.width ' + vwAnimator.width); if (vwAnimator.width !== 180) { vwAnimator.width = vwAnimator.width + 1; // Ti.API.info('vwAnimator.width ' + vwAnimator.width); } else { clearInterval(interval); } }, 1000); }); window.add(expandView);