Problem
When closing a tab group followed by creating and opening a new tab group, the application crashes.
Steps to reproduce
1. The app starts and the first tab group is opened
2. Click on the button to close the first tab group and create and open another tab group
3. Application crashes
Code to reproduce
var rootWin = Ti.UI.createWindow({
backgroundColor : 'pink',
exitOnClose : true,
navBarHidden : true
});
rootWin.open();
var tabGroup = Ti.UI.createTabGroup();
var win1 = Ti.UI.createWindow({
backgroundColor : 'orange'
});
var aButton = Ti.UI.createButton({
title : 'Button',
height : Ti.UI.SIZE,
width : Ti.UI.SIZE
});
aButton.addEventListener('click', function() {
tabGroup.close();
tabGroup = null;
var tabGroup2 = Ti.UI.createTabGroup();
var win21 = Ti.UI.createWindow({
backgroundColor : 'orange'
});
var tab21 = Ti.UI.createTab({
window : win21
});
tabGroup2.addTab(tab21);
tabGroup2.open();
});
win1.add(aButton);
var win2 = Ti.UI.createWindow({
backgroundColor : 'lime'
});
var tab1 = Ti.UI.createTab({
window : win1
});
var tab2 = Ti.UI.createTab({
window : win2
});
tabGroup.addTab(tab1);
tabGroup.addTab(tab2);
tabGroup.open();
Expected behavior
First tab group is closed and new tab group is opened.
Actual behavior
Application crashes
Please find attached the crash log.
Window open is an asynchronous operation and it is not safe to assume that the Tab Group will not be opened as the root activity for the task. Both the window and tab group are basically in a race to be the root activity. If a true chaining is desired (first window then tab group), it is possible to open the tab group once the window has been opened via open event listener. The default behavior of the application should be to exit when the root activity is closed.
Verified on: SDK: 2.2.0.v20120907162025 STUDIO: 2.1.3.201209071738 Devices: Samsung galaxy note(v 2.3.6), iOS simulator According to Opie Cyrus comment,tab group is opened after window is opened via open event listener. Following code is being used to test the scenario: var rootWin = Ti.UI.createWindow({ backgroundColor : 'pink', exitOnClose : true, navBarHidden : true }); rootWin.addEventListener('open', function(e) { var tabGroup = Ti.UI.createTabGroup(); var win1 = Ti.UI.createWindow({ backgroundColor : 'orange' }); var aButton = Ti.UI.createButton({ title : 'Button', height : Ti.UI.SIZE, width : Ti.UI.SIZE }); aButton.addEventListener('click', function() { tabGroup.close(); tabGroup = null; var tabGroup2 = Ti.UI.createTabGroup(); var win21 = Ti.UI.createWindow({ backgroundColor : 'orange' }); var tab21 = Ti.UI.createTab({ window : win21 }); tabGroup2.addTab(tab21); tabGroup2.open(); }); win1.add(aButton); var win2 = Ti.UI.createWindow({ backgroundColor : 'lime' }); var tab1 = Ti.UI.createTab({ window : win1 }); var tab2 = Ti.UI.createTab({ window : win2 }); tabGroup.addTab(tab1); tabGroup.addTab(tab2); tabGroup.open(); }); rootWin.open();