Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-4947] Android: Window close event not fired for heavyweight window

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2012-01-04T16:45:28.000+0000
Affected Version/sRelease 1.7.3
Fix Version/sSprint 2011-41, Release 1.7.4, Release 1.8.0
ComponentsAndroid
Labelsmodule_window, qe-testadded
ReporterIvan Skugor
AssigneeAllen Yeung
Created2011-08-09T07:35:05.000+0000
Updated2014-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]

Comments

  1. Allen Yeung 2011-09-13

    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.
  2. Ivan Skugor 2011-10-03

    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:
       var win = Ti.UI.createWindow({
           modal: true,
           backgroundColor: '#000'
       });
        
       win.addEventListener('close', function() {
           Ti.API.info('Close event fired');
       });
        
       var button = Ti.UI.createButton({
           width: 300,
           title: 'Close window!'
       });
        
       button.addEventListener('click', function() {
           win.close();
       });
        
       win.add(button);
        
       win.open();
       
    If you run this example, there is no output in the console. If you comment out "modal: true", the output is produced as expected.
  3. Ivan Skugor 2011-10-19

    With latest 1.8 build, I can confirm that this issue is fixed. Tnx :)
  4. Michael Pettiford 2011-10-20

    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
  5. Eric Merriman 2011-12-07

    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.
  6. Michael Pettiford 2012-01-04

    Reopening/closing to add/remove labels
  7. Shameer Jan 2013-12-10

    Anvil testcase PR https://github.com/appcelerator/titanium_mobile/pull/4967

JSON Source