Titanium Community Questions & Answer Archive

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

navBarHidden: true works, but then setinterval quits working properly?

Howdy,
I have a fun little 'hello world' related app I'm making to get to know Titanium. It works GREAT, changing the value of a label once per second. However, when I add navBarHidden: true when creating a window, setinterval only runs twice or so, then gets stuck.

This is happening with my android emulator. Do I need to address this differently?:

Titanium.UI.setBackgroundColor('#000');

var app = Titanium.UI.createWindow({  
    title:'Amazing Newb App',
    backgroundColor:'#0099FF',
    navBarHidden: true
});


var label = Titanium.UI.createLabel({
    color:'#FFFFFF',
    text:'Yay for mobile apps!',
    font:{fontSize:25,fontFamily:'Helvetica Neue'},
    textAlign:'center',
    width:'auto'
});

var blinkVis = 1;

app.add(label);

app.open({});

setInterval(function () {
    if(blinkVis == 1) {
        label.text = "Whoohooo!";
        blinkVis = 0;
    } else {
        label.text = "Yay for mobile apps!";
        blinkVis = 1;
    }
}, 1000);

Thanks much in advance,

Chris

— asked October 10th 2010 by Christopher Stevens
  • android
  • droid
  • emulator
  • navbarhidden
  • setinterval
2 Comments
  • So far I've found a hackish fix here: http://developer.appcelerator.com/question/48871/android-navbarhidden-on-app-start . It works for what I need, but it may get wiped once in a while with full rebuilds. Any thoughts on other more permanent work-arounds, or better coding practices? Thanks again.

    — commented October 10th 2010 by Christopher Stevens
  • This post discussing the use of one "dummy tab" seems to be pretty useful as well: http://developer.appcelerator.com/question/3651/tabgroup-as-starting-point-required

    — commented October 10th 2010 by Christopher Stevens

1 Answer

  • To answer my own question, it helps to launch a window that has its own js file. For example, app.js would look something like this for my droid phone (exitOnClose:true is droid specific):

    var win = Titanium.UI.createWindow({
         url:"main.js",
         title:"loading...",
         navBarHidden:true,
         exitOnClose:true
    });
    

    main.js would look something like this:

    var app = Titanium.UI.currentWindow;
    //add views and such here and have a very productive day!
    

    I made a little app that seems to work great on my droid (not only does the text blink, it spins!). Also, no tabs! I can't wait to progress further. Feel free to critique if you have any suggestions. :)

    Chris

    — answered October 11th 2010 by Christopher Stevens
    permalink
    2 Comments
    • The heavyweight window gives you a real Android Activity that response to the lifecycle events. So when your activity is resumed and paused the timers should also do the same to not chew up battery in the background.

      — commented October 12th 2010 by Don Thorp
    • Hmm, OK I'm learning more about Android services. I can probably work around the original issue mentioned. Feedback still welcome.

      — commented July 14th 2011 by Christopher Stevens
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.