I have a tableview with data loaded from a restful web service. I also have a "Reload" button. Both of them use a HttpClient to get the data from the ws. This usually works great. But.. if the app was idle for some time and I tap on "Reload", the HttpClient always returns SocketTimeoutException. If I try again, it works. So the problem is only the first time after the app was idle. What is the cause of this? How can I solve it?
This issue appears in Android and iOS.
This is the code that makes the request:
var client = Ti.Network.createHTTPClient({ onload : function(e) { if (callback) { callback(this.status, true, this.responseText, null); } }, onerror : function(e) { if (callback) { callback(this.status, false, this.responseText, e.error); } }, timeout : 5000 }); client.open(method, url); var loginPass = Ti.Utils.base64encode("username"+':'+ "password"); client.setRequestHeader('Authorization', 'Basic ' + loginPass); client.setRequestHeader("Content-Type", "application/json; charset=utf-8"); if(OS_IOS) { client.send(payload); } if(OS_ANDROID) { client.send(JSON.stringify(payload)); }