Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-1954] Android: removeEventListener has no effect when removing from a view in another context

GitHub Issuen/a
TypeBug
PriorityMedium
StatusClosed
ResolutionFixed
Resolution Date2011-04-17T01:57:38.000+0000
Affected Version/sn/a
Fix Version/sRelease 1.5.0
ComponentsAndroid
Labelsandroid, defect
ReporterBill Dawson
AssigneeBill Dawson
Created2011-04-15T03:06:24.000+0000
Updated2011-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.

Comments

  1. Bill Dawson 2011-04-15

    (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...

  2. Thomas Huelbert 2011-04-15

    1.4.2.4ce7ff G1 running 1.6, 2.2 simulator

JSON Source