{ "id": "85676", "key": "TIMOB-7505", "fields": { "issuetype": { "id": "1", "description": "A problem which impairs or prevents the functions of the product.", "name": "Bug", "subtask": false }, "project": { "id": "10153", "key": "TIMOB", "name": "Titanium SDK/CLI", "projectCategory": { "id": "10100", "description": "Titanium and related SDKs used in application development", "name": "Client" } }, "fixVersions": [], "resolution": null, "resolutiondate": null, "created": "2012-01-29T22:51:37.000+0000", "priority": { "name": "Low", "id": "4" }, "labels": [], "versions": [ { "id": "12580", "description": "Dual Runtime 1.8.0", "name": "Release 1.8.0.1", "archived": true, "released": true, "releaseDate": "2011-12-22" } ], "issuelinks": [], "assignee": { "name": "ingo", "key": "ingo", "displayName": "Ingo Muschenetz", "active": true, "timeZone": "America/Los_Angeles" }, "updated": "2015-04-13T20:12:14.000+0000", "status": { "description": "The issue is open and ready for the assignee to start work on it.", "name": "Open", "id": "1", "statusCategory": { "id": 2, "key": "new", "colorName": "blue-gray", "name": "To Do" } }, "components": [ { "id": "10202", "name": "Android", "description": "Android Platform" } ], "description": "h2. Problem\r\n\r\naddEventListener in another event listener is not removed by removeEventListener.\r\n\r\nh2. Test Case\r\n\r\nEvery time the button is clicked, one extra \"blurListener\" is added, each resulting in a message on log. Thus, the removeEventListener is not working.\r\n\r\n\r\n{code:lang=javascript|title=app.js}\r\nTi.UI.setBackgroundColor('#000');\r\n\r\nvar win1 = Ti.UI.createWindow({\r\n\ttitle: 'Win1',\r\n\tfullscreen: true\r\n});\r\n\r\nvar win2 = Ti.UI.createWindow({\r\n\ttitle: 'Win2',\r\n\tfullscreen: true\r\n});\r\n\r\nvar btn = Ti.UI.createButton({\r\n\ttitle: 'Button',\r\n\ttop: 10\r\n});\r\nwin1.add(btn);\r\n\r\nvar lbl = Ti.UI.createLabel({\r\n\ttext: 'Label',\r\n\ttop: 10\r\n});\r\nwin2.add(lbl);\r\n\r\nvar i = 0;\r\nvar blurListener = function() {\r\n\tTi.API.info('blurListener: ' + (i++));\r\n\twin1.removeEventListener('blur', blurListener);\r\n};\r\n\r\nbtn.addEventListener('click', function() {\r\n\twin1.addEventListener('blur', blurListener);\t\r\n\t\r\n\tTi.API.info('---');\r\n\twin2.open({\r\n\t\tanimated: true\r\n\t});\r\n});\r\n\r\nwin1.open();\r\n{code}\r\n\r\nh3. Workaround\r\nYou can solve the problem by overriding the addEventListener and removeEventListener prototypes of the Titanium.UI.Window objects. Just insert the code below into the app.js.\r\n\r\n{code:javascript}\r\n(function() {\r\n\tif (Ti.Platform.name == 'android') {\r\n\t\tvar _addEventListener = Ti.UI.Window.prototype.addEventListener;\r\n\t\tvar _removeEventListener = Ti.UI.Window.prototype.removeEventListener;\r\n\t\t\r\n\t\tTi.UI.Window.prototype._eventListener = function(e) {\r\n\t\t\tif (typeof e.source == 'undefined') return;\r\n\t\t\tif (e.source.toString() != '[object TiBaseWindow]') return;\r\n\t\t\tvar listeners = e.source._eventListeners[e.type];\r\n\t\t\tfor (var i=0; i