Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-1827] Android: window close event firing multiple times

GitHub Issuen/a
Resolution Date2012-03-11T22:20:25.000+0000
Affected Version/sn/a
Fix Version/sRelease 1.6.0 M03, Sprint 2012-02, Release 2.0.0, Release 1.8.1
Labelsparity, qe-testadded, release-1.6.0
ReporterBill Dawson
AssigneeHieu Pham


In this simple example, if you click the close button in the second window the close event listener runs FOUR times:

/*global Ti, Titanium, alert */
var win1 = Titanium.UI.createWindow({  title:'Test', backgroundColor:'#fff', fullscreen: true, exitOnClose: true });

var win2 = Ti.UI.createWindow({title:'window 2', fullscreen:true, backgroundColor: 'green'});

var open = Ti.UI.createButton({title: 'open'});
open.addEventListener('click', function(){win2.open();});

var close = Ti.UI.createButton({title: 'close'});
close.addEventListener('click', function(){win2.close();});


Note: if you click the back button instead of clicking the close button, it fires only once.




  1. Bill Dawson 2011-04-15

    After this is fixed see if it helps at all with the OOM experienced by Friedrich Seydel in https://appcelerator.lighthouseapp.com/projects/32238/tickets/1767-android-event-listeners-in-reopened-window-do-not-fire#ticket-1767-11"> this comment from ticket 1827.

  2. Bill Dawson 2011-04-15

    Assign to Don for milestone/priority. (Feel free to assign back! :) )

  3. Bill Dawson 2011-04-15

    cf #1489 re the backgroundImage and OOM

  4. Don Thorp 2011-04-15

    Related to Activity refactor. There are multiple close paths through the different exit methods that can fire 1 to n events.

  5. Jeff 2011-04-15

    Please change that back to 1.5 and make sure this issue is resolved in the Q4 release. This is a critical issue and we've had to work around this for 2 major projects and over 9 months.

    If Android is not going to receive the attention it needs to be stable, we will be canceling our account and moving to another cross-platform development suite at the first of the year.

  6. Don Thorp 2011-04-15

    Unfortunately 1.5.0 is fully planned and we're working to get it shipped in December. I've created a new 1.5.1 M01 milestone and I'm moving this ticket there so we can start working on it as soon as 1.5.0 is out the door. It will then be available from the CI build.

  7. Scott 2011-04-15

    This is a major problem for me as well. Is there any workaround any one can think of at the moment until this bug is fixed and any ideas when a fix for this will be complete?

  8. jimwilliams 2011-04-15

    I'm opening windows and showing them modally. Since javascript allows methods and properties to be added dynamically to an object, I can get around this problem with code like this (from the example above):

       var win2 = Ti.UI.createWindow({title:'window 2', fullscreen:true, backgroundColor: 'green'});
       win2.CloseFired = false;
          if (this.CloseFired) return;
          this.CloseFired = true;
          // do what needs to be done 

    It's not very sophisticated, but seems to do the trick.

  9. jimwilliams 2011-04-15

    Quick follow-up; the technique I used above works ok for Android, but not for iPhone which seems to somehow reuse the windows/listeners. I've made the fix conditional for Android only in my code and both seem to now work as expected.

  10. Bill Dawson 2011-04-15

    To QA:

    To test this, use attached CloseTest.zip (import the project therein). When you run it, you should see only one close event (in the console / logcat) when you close the windows that are opened with the "no url" buttons -- in fact, with the failing version of the SDK, you'll see 3 per closure, which is a bug. For the "own url" windows, you should see two (one from an event listener created in the main window, one from an event listener created inside the second window's own JS file), but you'll see six.

  11. Bill Dawson 2011-04-15

    (from [4ede763ab6c786a90f2e0397152d78b0a79781f5]) [#1827 state:fixed-in-qa] Fix multiple window close event firings by making sure that the multiple possible code paths from a window closure still only result in one close event being fired. https://github.com/appcelerator/titanium_mobile/commit/4ede763ab6c786a90f2e0397152d78b0a79781f5"> https://github.com/appcelerator/titanium_mobile/commit/4ede763ab6c7...

  12. Thomas Huelbert 2011-04-15

    confirmed on a G2 running 2.2 and a g1 running 1.6. [INFO] Titanium SDK version: 1.6.0 (12/28/10 10:46 4ede763). results as Bill describes.

  13. Wilson Luu 2012-01-10

    Reopening bug. Both test cases attached to this bug fails in the following environment: SDK build: Runtime: V8, Rhino Titanium Studio, build: Device: Nexus S (2.3.6) Note: For both test cases, the bug does not appear in sdk build *1.7.5*
  14. Shawn Lipscomb 2012-01-16

    I get the close event twice on a heavyweight url-based window. SDK and 1.9.0.v20120111233134.
  15. Paul Dowsett 2012-01-16

    This issue still exists for Continuous Build Titanium 1.9.0 (2012/01/16 11:16 366b32d) and v8 runtime (rhino not tested)
  16. Michael Pettiford 2012-01-25

    Reopening issue Tested with Ti Studio build Ti Mob SDK 1.8.1.v20120124200134 OSX Lion Android Emulator 2.2 Both test cases failed (fail case in description and Bill's test app) by producing two close events
  17. Opie Cyrus 2012-01-25

    fixed in 1.9 master.
  18. Michael Pettiford 2012-01-28

    Closing issue Tested with Ti Studio build Ti Mob SDK 1.8.1.v20120127173134 OSX Lion Nexus S OS 2.2.2 Verified that only one window close event is fired
  19. Michael Pettiford 2012-01-30

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

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

JSON Source