[TIMOB-4947] Android: Window close event not fired for heavyweight window
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | High |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2012-01-04T16:45:28.000+0000 |
Affected Version/s | Release 1.7.3 |
Fix Version/s | Sprint 2011-41, Release 1.7.4, Release 1.8.0 |
Components | Android |
Labels | module_window, qe-testadded |
Reporter | Ivan Skugor |
Assignee | Allen Yeung |
Created | 2011-08-09T07:35:05.000+0000 |
Updated | 2014-06-19T12:46:23.000+0000 |
Description
The
close
event is not fired when window close()
method is called for heavyweight windows (enabling modal or fullscreen etc). However, lightweight windows work as expected. I (the reporter) have tested this with all versions from 1.7.x branch, 1.8.0 latest also has this issue, while this works with 1.6.x branch. Here is code that reproduces this issue:
var win = Ti.UI.createWindow({
modal: true,
// fullscreen:'true',
backgroundColor: '#000'
});
var button = Ti.UI.createButton({
width: 300,
title: 'Close window, log events!'
});
win.add(button);
win.open();
button.addEventListener('click', function() {
Ti.API.info('Button click event fired');
win.close();
});
win.addEventListener('close', function() {
Ti.API.info('Window close event fired');
});
No output is generated when this code is run and the button is clicked. Comment out the modal and fullscreen properties and the output will be generated as expected.
If a delay is introduced, using setTimeout(), the event for heavyweight windows is also fired:
var win = Ti.UI.createWindow({
// modal: true,
// fullscreen:'true',
backgroundColor: '#000'
});
var button = Ti.UI.createButton({
width: 300,
title: 'Close window, log events!'
});
win.add(button);
win.open();
button.addEventListener('click', function() {
Ti.API.info('Button click event fired');
setTimeout(function(){
win.close(); // *** INSIDE setTimeout() ***
}, 1000);
});
win.addEventListener('close', function() {
Ti.API.info('Window close event fired');
});
Also note that the event is not fired if the windows is simply opened and immediately closed:
var win = Ti.UI.createWindow({
// modal: true,
fullscreen:'true',
backgroundColor: '#000'
});
win.open();
win.close();
win.addEventListener('close', function() {
Ti.API.info('Window close event fired');
});
However, it works as expected if wrapped in setTimeout():
var win = Ti.UI.createWindow({
// modal: true,
fullscreen:'true',
backgroundColor: '#000'
});
win.open();
setTimeout(function(){
win.close();
}, 1000);
win.addEventListener('close', function() {
Ti.API.info('Window close event fired');
});
Q/A topics:
[http://developer.appcelerator.com/question/123902/close-event-not-fired-when-window-is-closed-from-button-event-handler]
[http://developer.appcelerator.com/question/123821/android-window-close-event-not-firing]
I wasn't able to reproduce this with both modal and fullscreen enabled. For the other scenario, there is typically a small delay after you initially create a window. If you immediately close a window right after you open one, it may not fire a close event. Also, in the example mentioned above, the event listener is added after the window is closed, which is why the event listener code is never triggered.
Hi Allen. Focus on the first example. In it, window is closed when button is clicked (so window close event handler is attached at that time), but "close" event is not fired. Here is my original use case that I tested with (and again right now with latest 1.7.3) and it doesn't work as expected:
If you run this example, there is no output in the console. If you comment out "modal: true", the output is produced as expected.
With latest 1.8 build, I can confirm that this issue is fixed. Tnx :)
Tested with 1.7.4.v20111019130614 with TiStudio 1.0.6.201110171921 on OSX Lion 10.7.2 Nexus S with OS version 2.3.6 -- G Slate with OS version 3.1 -- HTC hero with OS version 2.1 Android emulator with OS version 2.1 and 2.3.3 Window close event is fired after button click and log is displaying respective output (i.e. 'Close event fired') Keeping open to confirm with 1.8 before closing
Verified fixed with SDK 1.8.0.1.v20111207112258 in both Rhino and V8 on Nexus S 2.3.6 and Droid 3 2.3.4 using Titanium Studio, build: 1.0.7.201112061404.
Reopening/closing to add/remove labels
Anvil testcase PR https://github.com/appcelerator/titanium_mobile/pull/4967