Titanium Community Questions & Answer Archive

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

Adding a window to the stack

I'm trying to do something pretty simple here: add a new window (containing a webview) to the window stack. The window does open and I can see the webview, but pressing the Android back button closes out the application instead of taking me to the previous window as I would expect. This is my app.js where I'm loading my initial window, and handling an event that opens the new window:


// Create root window
var mainWindow = Titanium.UI.createWindow({
    backgroundColor: '#FFFFFF'

var webview = Titanium.UI.createWebView({
    url: 'Home.html'


// Event handlers for clicks on the home page
Ti.App.addEventListener('webview_open_window', function(e) {
    var web = Titanium.UI.createWebView({
        url: e.windowURL

    var win = Titanium.UI.createWindow({
        backgroundColor: '#FFFFFF'


It seems like the window that I'm creating in the event handler is just replacing whatever is already on the window stack instead of being pushed on top of it. What am I doing wrong?

This is with SDK 1.0 on Android. Thanks!

— asked March 16th 2010 by Scott Metoyer
  • android
  • createwindow
  • mobile
  • stack
  • window

7 Answers

  • On Android, windows have the concept of being "lightweight" and "heavyweight". Lightweight windows act as containers within the current window exactly like a plain view. The only real difference is that windows can be opened and closed, views can't. To force a heavyweight window in Android you currently need to do one of the following things.

    • Provide a url when you open it.
    • use the fullscreen or navBarHidden property in the creation option.

    The simplest is to do something like.

    var win = Titanium.UI.createWindow({ fullscreen : false});
    — answered March 16th 2010 by Don Thorp
    1 Comment
    • @Don
      This is not working.

      — commented August 22nd 2012 by Ashwin Bhanushali
  • Using fullscreen windows for secondary windows seems to be somewhat of a hack and not in keeping with the Android API since it hides the standard Status bar and leaves the application user with a horrible experience.

    I found that using win2.open({modal:true}); will make the second window a heavyweight window and allow the back button to function correctly.

    Also, the visibility check did not seem to work, but forcing a win2.close(); before opening the secondary window seemed to do the trick.

    — answered July 31st 2010 by Joe Brinkman
    1 Comment
    • Hey Joe following is the code I am using to open a window2 from window1

          var win2 = Ti.UI.createWindow({
                          backgroundColor : 'white',
                          url : 'ui/common/AlbumWindow.js',
                          fullscreen : false

      But when I click back button after opening window2 my application is closed.
      Please help me to solve this issue.

      — commented August 22nd 2012 by Ashwin Bhanushali
  • Ok, that works, but then how do I navigate back and forth?

    1. I open win1 with a button
    2. press button, on click, open() win2
    3. press <- to get to win1
    4. press button, on click, nothing

    I tried

        if (!win2.visible) {

    but this doesnt work.


    — answered May 24th 2010 by Dan Trevino
    • It appears to me that the back button on the Android platform will KILL whatever window you are in - my testing here (http://developer.appcelerator.com/question/57121/exitonclose-not-functioning-on-android) - seemed to indicate that as well. In Dan's example above, win2 is null after you hit the backButton on win2.

      — commented September 1st 2010 by Ben Wilson
    • I have the same issue as Dan. I have win1, I open win2 with {fullscreen: false}, then I go back to win1 by pressing the back button, and I successfully go back to win1. But, then I try to open win2 again with the same interaction, but nothing happens. Actually I realized that, in this situation, the "click" event is not even fired from my button on win1. It seems like going back to my previous window with the back button had an effect on the views within win1.

      That would be great also if the Window could have a set of events for its visibility, just like on Android with onPause(), onResume(), onStart(), onStop().

      [Titanium 1.4 - Android 1.6]

      — commented September 6th 2010 by Jordan Bonnet
    • My mistake for the event not working. I was actually using a SearchBar, and most of the events are not fired, and the focus event is not fired if the SearchBar is already focused, which I believe is the right behavior. Thus, it was a side effect, sorry about that.

      — commented September 6th 2010 by Jordan Bonnet
  • Dan,

    I read on one of the other threads about using a win2.close() before the win2.open(). I used that in my app and it worked great.

    — answered August 7th 2010 by Joe Brinkman
  • modal:true

    — answered March 21st 2013 by Aparna M
  • Had the same symptoms while debugging an app: Android would quit on closing the window, no matter if I pressed the back button or if I close it myself with a close button calling window.close(), while iOS was working fine (only popping the current window).

    Turns out I had exitOnClose:true when I created the window:

    var window = Ti.UI.createWindow({
        backgroundColor: 'white',
        exitOnClose: true,
        fullscreen: true

    Apparently exitOnClose is only working on Android, and if set it's REALLY working :)

    Hope this helps.

    — answered June 12th 2014 by Simion Dragan
  • just use: var win = Titanium.UI.currentWindow;

    — answered May 29th 2013 by desdes desdes
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.