Titanium Community Questions & Answer Archive

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

Window Pointers

I am trying to write a singleton window program. Where each window knows which windows are currently opened. I have tried to store the window pointer into an array which i then pass between the windows but it is not working. I have even tried Ti.App.Properties.setString('windows', JSON.stringify(windowsArray)); and then fetching them back on each window later with the JSON.parse(Ti.App.Properties.getString('windows')); but it doesnt work it just returns {{}} I was wondering if there is a solution to window pointers or what i can do so that windows will know what windows are open. Custom Events will not work for this app. Please Help, i am up to any suggestions.


I came up with a solution for this. If anyone has a better solution let me know. This is a way simplified version of what i implemented, but it works. I actually have a custom Window class that keeps track of all windows, creates them, opens them and has events to add and remove from the array. but i hope this is enough for someone to get started.


var windows = [];

var win1 = Ti.UI.createWindow({
    url: 'external.js',
    name: 'External Window 1'
win1.windows = windows;

var win2 = Ti.UI.createWindow({
    url: 'external2.js',
    name: 'External Window 2'
win2.windows = windows;


var win = Ti.UI.currentWindow;
var windows = win.windows;

for(var i = 0; i < windows.length; i++) {
    Ti.API.info('win'+i+' = '+windows[i].name);


var win = Ti.UI.currentWindow;
var windows = win.windows;

for(var i = 0; i < windows.length; i++) {
    Ti.API.info('win'+i+' = '+windows[i].name);

The output on each window should be something like

[INFO] win0 = External Window 1
[INFO] win1 = External Window 2
— asked June 29th 2010 by Kevin Smithson
  • iphone
  • pointers
  • windows

2 Answers

  • Do you mean a window 'per tab'?

    You could always have a var in app.js called something like 'currentWindow' and set the value to the name of your window using the 'focus' event for the window.

    You could even set it to be the actual Ti.UI.currentWindow object if that makes sense for your app.

    — answered June 30th 2010 by Kosso
    1 Comment
    • i have tried using the Ti.UI.currentWindow object but when i serialize it i lose the pointer to it. I could try the focus event when i get to work tomorrow. I will let you guys know if it works.

      — commented June 30th 2010 by Kevin Smithson
  • funny, i just wanted to ask the same question

    in android fyi this seems to work, cause a pointer to a window seems to be an object id while on iphone you only get the type of the object

    on android i use this behaviour for creating a tabgroup using window for its content area

    — answered June 30th 2010 by Christian Sigl
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.