Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-26996] Android: Window/TabGroup close() method call is ignored until "open" event has been fired

GitHub Issuen/a
TypeBug
PriorityNone
StatusClosed
ResolutionFixed
Resolution Date2019-04-29T13:20:17.000+0000
Affected Version/sn/a
Fix Version/sRelease 8.0.1
ComponentsAndroid
LabelsTabGroup, android, close, engSchedule, window
ReporterJoshua Quick
AssigneeJoshua Quick
Created2019-04-26T00:38:24.000+0000
Updated2019-04-29T13:20:17.000+0000

Description

*Summary:* On Android, a Ti.UI.Window or Ti.UI.TabGroup object's close() method call is ignored if it hasn't finished opening yet. The Window or TabGroup will remain open and not automatically close itself. This means the following won't close the window. The window will remain open.
var window = Ti.UI.createWindow();
window.open();
window.close();  // <- This method call will be ignored.
*Steps to reproduce:*

Build and run the below code on Android.

Tap on the "Open/Close Window" button.

Notice a red window is displayed. (This is a bug. The close() method was ignored.)

Press the Android "Back" button.

Tap on the "Open/Close TabGroup" button.

Notice a red tab group is displayed. (This is a bug. The close() method was ignored.)

var parentWindow = Ti.UI.createWindow();
var openWindowButton = Ti.UI.createButton({
	title: "Open/Close Window",
	top: "30%",
});
openWindowButton.addEventListener("click", function() {
	var childWindow = Ti.UI.createWindow({ backgroundColor: "red" });
	childWindow.add(Ti.UI.createLabel({
		text: "Uh-oh!",
		color: "white",
	}));
	childWindow.open();
	childWindow.close();  // <- This method call will be ignored.
});
parentWindow.add(openWindowButton);
var openTabGroupButton = Ti.UI.createButton({
	title: "Open/Close TabGroup",
	top: "50%"
});
openTabGroupButton.addEventListener("click", function() {
	function createTab(title) {
		var window = Ti.UI.createWindow({ title: title, backgroundColor: "red" });
		window.add(Ti.UI.createLabel({ text: "Uh-oh!", color: "white" }));
		var tab = Ti.UI.createTab({
			title: title,
			window: window,
		});
		return tab;
	}
	var tabGroup = Ti.UI.createTabGroup({
		tabs: [createTab("Tab 1"), createTab("Tab 2"), createTab("Tab 3")],
	});
	tabGroup.open();
	tabGroup.close();  // <- This method call will be ignored or crash in older versions.
});
parentWindow.add(openTabGroupButton);
parentWindow.open();
*Note:* For TabGroup, calling the close() method will crash if the app was built with Titanium 7.x.x or older versions. In Titanium 8.0.0, it does not crash and the method call is ignored. *Expected Result:* The close() method call should be respected, eve before the window has finished opening. This is how it works on iOS. The only time close() should be ignored is if the window has never been opened or has already been closed. *Work-around:* Don't call the close() method until the "open" event has been fired.

Comments

  1. Joshua Quick 2019-04-26

    PR (master): https://github.com/appcelerator/titanium_mobile/pull/10829
  2. Joshua Quick 2019-04-26

    PR (8.0.x): https://github.com/appcelerator/titanium_mobile/pull/10868
  3. Lokesh Choudhary 2019-04-26

    FR passed PR merged.
  4. Samir Mohammed 2019-04-29

    Closing ticket, fix verified in SDK version 8.0.1.v20190426162041 and SDK version 8.1.0.v20190426222341 Test and other information can be found at: Master : https://github.com/appcelerator/titanium_mobile/pull/10829 8_0_X: https://github.com/appcelerator/titanium_mobile/pull/10868

JSON Source