{ "id": "63601", "key": "TIMOB-2969", "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": { "id": "2", "description": "The problem described is an issue which will never be fixed.", "name": "Won't Fix" }, "resolutiondate": "2017-07-28T19:30:01.000+0000", "created": "2011-04-15T03:33:54.000+0000", "priority": { "name": "High", "id": "2" }, "labels": [ "api" ], "versions": [ { "id": "13505", "description": "Release 3.0.0", "name": "Release 3.0.0", "archived": true, "released": true, "releaseDate": "2012-12-14" } ], "issuelinks": [ { "id": "20429", "type": { "id": "10003", "name": "Relates", "inward": "relates to", "outward": "relates to" }, "inwardIssue": { "id": "63602", "key": "TIMOB-2970", "fields": { "summary": "Android: event listeners on modules and from heavyweight windows cannot show alerts.", "status": { "description": "The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.", "name": "Closed", "id": "6", "statusCategory": { "id": 3, "key": "done", "colorName": "green", "name": "Done" } }, "priority": { "name": "Low", "id": "4" }, "issuetype": { "id": "1", "description": "A problem which impairs or prevents the functions of the product.", "name": "Bug", "subtask": false } } } } ], "assignee": { "name": "ingo", "key": "ingo", "displayName": "Ingo Muschenetz", "active": true, "timeZone": "America/Los_Angeles" }, "updated": "2017-07-28T19:30:01.000+0000", "status": { "description": "The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.", "name": "Closed", "id": "6", "statusCategory": { "id": 3, "key": "done", "colorName": "green", "name": "Done" } }, "components": [ { "id": "10202", "name": "Android", "description": "Android Platform" } ], "description": "{html}

This is most notable if the event listener is added to a\r\nmodule as opposed to another type of proxy,\r\nbecause modules are effectively singletons (created once in the\r\nroot context) and therefore their event listener collections\r\nsurvive long.

\r\n

As a sample failcase, create a new Ti project and make this the\r\napp.js:

\r\n
\r\nTitanium.UI.setBackgroundColor('#000');\r\nvar win = Titanium.UI.createWindow({  \r\n    title:'Test',\r\n    backgroundColor:'#fff',\r\n    exitOnClose: true\r\n});\r\n\r\nvar btn = Ti.UI.createButton({\r\n    title: 'Open second window'\r\n});\r\nbtn.addEventListener('click', function() {\r\n    Ti.UI.createWindow({\r\n        url: 'win.js',\r\n        backgroundColor: 'black',\r\n        fullscreen: false\r\n    }).open();\r\n});\r\nwin.add(btn);\r\nwin.open();\r\n
\r\n

Then create a new file, win.js, with this in it:

\r\n
\r\nvar win = Ti.UI.currentWindow;\r\nTi.App.addEventListener('test_event', function(){Ti.API.info(\"TEST EVENT LISTENER\");});\r\nvar btn = Ti.UI.createButton({\r\n    top: 10, left: 30, right: 30, height: 40,\r\n    title:'Fire event'\r\n});\r\nbtn.addEventListener('click',function(){\r\n    Ti.App.fireEvent('test_event', {});\r\n});\r\nwin.add(btn);\r\n\r\nvar btnClose = Ti.UI.createButton({\r\n    top: 60, left: 30, right: 30, height: 40,\r\n    title: 'Close window'\r\n});\r\nbtnClose.addEventListener('click', function(){win.close();});\r\nwin.add(btnClose);\r\n
\r\n

Run the application and do the following:

\r\n\r\n

If you keep going back and forth between the windows like this,\r\nyou'll keep getting more and more \"TEST EVENT LISTENER\" info\r\nmessages -- these are event listeners stranded from all the other\r\ntimes that the second window was opened.

\r\n

It could be argued that our user-devs are responsible for\r\nremoving event listeners when they are no longer wanted, such as\r\nwhen a heavyweight window closes and that heavyweight window's JS\r\ncode created the event listeners. However, this problem does not\r\nexist on iPhone.

{html}", "attachment": [], "flagged": false, "summary": "Android: event listeners orphaned from their contexts continue to be invoked", "creator": { "name": "billdawson", "key": "billdawson", "displayName": "Bill Dawson", "active": true, "timeZone": "Europe/Berlin" }, "subtasks": [], "reporter": { "name": "billdawson", "key": "billdawson", "displayName": "Bill Dawson", "active": true, "timeZone": "Europe/Berlin" }, "environment": null, "comment": { "comments": [ { "id": "129782", "author": { "name": "billdawson", "key": "billdawson", "displayName": "Bill Dawson", "active": true, "timeZone": "Europe/Berlin" }, "body": "{html}

Assigning to Don for milestoning

{html}", "updateAuthor": { "name": "billdawson", "key": "billdawson", "displayName": "Bill Dawson", "active": true, "timeZone": "Europe/Berlin" }, "created": "2011-04-15T03:33:55.000+0000", "updated": "2011-04-15T03:33:55.000+0000" }, { "id": "216901", "author": { "name": "jyounus", "key": "jyounus", "displayName": "Junaid Younus", "active": true, "timeZone": "Europe/London" }, "body": "Tested on a Samsung Galaxy S2 using TiSDK 2.2.0v20120828153312, issue still valid. ", "updateAuthor": { "name": "jyounus", "key": "jyounus", "displayName": "Junaid Younus", "active": true, "timeZone": "Europe/London" }, "created": "2012-08-29T14:45:51.000+0000", "updated": "2012-08-29T14:45:51.000+0000" }, { "id": "425039", "author": { "name": "lmorris", "key": "lmorris", "displayName": "Lee Morris", "active": false, "timeZone": "America/Los_Angeles" }, "body": "Closing due to inactivity. If this issue still exists, please raise a new ticket.", "updateAuthor": { "name": "lmorris", "key": "lmorris", "displayName": "Lee Morris", "active": false, "timeZone": "America/Los_Angeles" }, "created": "2017-07-28T19:30:01.000+0000", "updated": "2017-07-28T19:30:01.000+0000" } ], "maxResults": 3, "total": 3, "startAt": 0 } } }