Titanium Community Questions & Answer Archive

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

bug: sometimes "setTimeout" doesn't work on Android

Hi,

Sometimes setTimeout works, sometimes setTimeout doesn't work on Android. Are there some conditions to make it work always?

Versions: Android APIs 2.1&2.2 and Titanium 1.6RC1

I tried the following simple code based on the app.js in the default project.

app.js:

Ti.include('test.js');

var tabGroup = Titanium.UI.createTabGroup();

setTimeout(function(){
        Ti.API.info('setTimeout A OK!');
}, 3000);

var win1 = Titanium.UI.createWindow({  
    title:'Tab 1',
    backgroundColor:'#fff'
});
var tab1 = Titanium.UI.createTab({  
    icon:'KS_nav_views.png',
    title:'Tab 1',
    window:win1
});

var label1 = Titanium.UI.createLabel({
    color:'#999',
    text:'I am Window 1',
    font:{fontSize:20,fontFamily:'Helvetica Neue'},
    textAlign:'center',
    width:'auto'
});

win1.add(label1);
tabGroup.addTab(tab1);  

tabGroup.open();

setTimeout(function(){
    Ti.API.info('setTimeout B OK!');
}, 3000);

test.js:

setTimeout(function(){
        Ti.API.info('setTimeout C OK!');
}, 3000);

(function(){
    setTimeout(function(){
        Ti.API.info('setTimeout D OK!');
    }, 3000);
})();

The all 4 info logs (A, B, C, D) are printed on iPhone perfectly, but no log on Android.

Thank you.

— asked February 19th 2011 by Studio Hitori
  • android
  • settimeout
1 Comment
  • Did you achieve that?!
    I can't too!

    — commented February 26th 2011 by Daniel Maceira

3 Answers

  • I have the same problem…

    edit: Seems to work you do it this way :

    var f = function(){
    
        }
        setTimeout(f,2000);
    
    — answered April 11th 2011 by ---------- ----------
    permalink
    0 Comments
  • Same issue. Works great when declared using the 'var' syntax.

    For reference here is the error I get when not using the var syntax.

    Wrapped Java.lang.
    IllegalArgumentException: Don't know how to callback of type: 
    org.appcelerator.Kroll.Proxy$1
    
    — answered April 11th 2011 by Justin Richards
    permalink
    0 Comments
  • Studio Hitori

    This issue has been raised in ticket #3184. If its resolution is important to you, then you can register with Lighthouse and watch it to receive updates by email about its status and ultimate fix.

    Please close this thread, so others can find this information easily.

    Many thanks for bring it to the community's attention. :)

    — answered April 12th 2011 by Paul Dowsett
    permalink
    0 Comments
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.