[TIMOB-1954] Android: removeEventListener has no effect when removing from a view in another context
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Medium |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2011-04-17T01:57:38.000+0000 |
Affected Version/s | n/a |
Fix Version/s | Release 1.5.0 |
Components | Android |
Labels | android, defect |
Reporter | Bill Dawson |
Assignee | Bill Dawson |
Created | 2011-04-15T03:06:24.000+0000 |
Updated | 2011-04-17T01:57:38.000+0000 |
Description
Sample failcase app.js:
/*global Ti, Titanium, alert, JSON */
Titanium.UI.setBackgroundColor('#000');
var win = Titanium.UI.createWindow({
title:'Test',
backgroundColor:'#fff',
fullscreen: true
});
function clickhandler() {
Ti.API.info('HELLO');
}
var btn1 = Ti.UI.createButton({
top: 0,
title: 'Say hello'
});
btn1.addEventListener('click', clickhandler);
win.add(btn1);
var btn2 = Ti.UI.createButton({
top: 60,
title: 'Remove hello click handler'
});
btn2.addEventListener('click', function() {
btn1.removeEventListener('click', clickhandler);
});
win.add(btn2);
win.open();
Note the fullscreen: true
in that script. This
makes the window being opened a "heavyweight" window that gets its
own activity and context. The code to remove the event listener
from one of the buttons on that window is defined in the root
context. This causes the removeEventListener
to have
no effect.
If you take away the fullscreen: true
in the window
creation arguments, the removeEventListener
will
succeed.
EXPECTED BEHAVIOR: The "HELLO" message will stop appearing in the console when you click the first button, IF you click the second button at least once.
(from [c6e1d2cdaa30d33e504163c750d55c41dda4063b]) [#1954 state:fixed-in-qa] Because we don't copy over pre-existing event listeners when a proxy switches contexts, when we remove a listener we need to remove it from the original context as well http://github.com/appcelerator/titanium_mobile/commit/c6e1d2cdaa30d33e504163c750d55c41dda4063b"> http://github.com/appcelerator/titanium_mobile/commit/c6e1d2cdaa30d...
1.4.2.4ce7ff G1 running 1.6, 2.2 simulator