[TIMOB-1827] Android: window close event firing multiple times
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | High |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2012-03-11T22:20:25.000+0000 |
Affected Version/s | n/a |
Fix Version/s | Release 1.6.0 M03, Sprint 2012-02, Release 2.0.0, Release 1.8.1 |
Components | Android |
Labels | parity, qe-testadded, release-1.6.0 |
Reporter | Bill Dawson |
Assignee | Hieu Pham |
Created | 2011-04-15T03:03:15.000+0000 |
Updated | 2013-12-10T06:18:54.000+0000 |
Description
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 */
Titanium.UI.setBackgroundColor('#000');
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'});
win2.addEventListener('close',function(){Ti.API.info('CLOSE');});
var open = Ti.UI.createButton({title: 'open'});
open.addEventListener('click', function(){win2.open();});
win1.add(open);
var close = Ti.UI.createButton({title: 'close'});
close.addEventListener('click', function(){win2.close();});
win2.add(close);
win1.open();
Note: if you click the back button instead of clicking the close button, it fires only once.
Attachments
File | Date | Size |
---|---|---|
closetest.zip | 2011-04-15T03:03:15.000+0000 | 772036 |
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.
Assign to Don for milestone/priority. (Feel free to assign back! :) )
cf #1489 re the backgroundImage and OOM
Related to Activity refactor. There are multiple close paths through the different exit methods that can fire 1 to n events.
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.
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.
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?
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):
It's not very sophisticated, but seems to do the trick.
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.
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.
(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...
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.
Reopening bug. Both test cases attached to this bug fails in the following environment: SDK build: 1.8.0.1 Runtime: V8, Rhino Titanium Studio, build: 1.0.8.201201091758 Device: Nexus S (2.3.6) Note: For both test cases, the bug does not appear in sdk build *1.7.5*
I get the close event twice on a heavyweight url-based window. SDK 1.8.0.1 and 1.9.0.v20120111233134.
This issue still exists for Continuous Build Titanium 1.9.0 (2012/01/16 11:16 366b32d) and v8 runtime (rhino not tested)
Reopening issue Tested with Ti Studio build 1.0.8.201201210622 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
fixed in 1.9 master.
Closing issue Tested with Ti Studio build 1.0.8.201201262211 Ti Mob SDK 1.8.1.v20120127173134 OSX Lion Nexus S OS 2.2.2 Verified that only one window close event is fired
Reopening/closing to add/remove labels
Anvil testcase PR https://github.com/appcelerator/titanium_mobile/pull/4967