Uploaded image for project: 'Titanium SDK/CLI'
  1. Titanium SDK/CLI
  2. TIMOB-4947

Android: Window close event not fired for heavyweight window

    Details

    • Type: Bug
    • Status: Closed
    • Priority: High
    • Resolution: Fixed
    • Affects Version/s: Release 1.7.3
    • Component/s: Android
    • Environment:

      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:

      app.js

      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:

      app.js

      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:

      app.js

      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():

      app.js

      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

        Attachments

          Activity

            People

            • Assignee:
              ayeung Allen Yeung
              Reporter:
              ivan.skugor Ivan Skugor
            • Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Backbone Issue Sync

                • Titanium SDK/CLI <> Titanium Mobile
                  Synced with:
                  TIMOB-4200
                  Sync status:
                  ERROR
                  Last received:
                  Last sent:

                  Git Integration