{ "id": "63602", "key": "TIMOB-2970", "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:21.000+0000", "created": "2011-04-15T03:33:56.000+0000", "priority": { "name": "Low", "id": "4" }, "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" }, "outwardIssue": { "id": "63601", "key": "TIMOB-2969", "fields": { "summary": "Android: event listeners orphaned from their contexts continue to be invoked", "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": "High", "id": "2" }, "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:21.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}
If an event listener is put on to a module and\r\nthe event listener itself is created in a heavyweight context --\r\nor, more specifically, is created outside the root context\r\n-- that event listener, when invoked, will be unable to\r\nsuccessfully display alert dialogs.
\r\nThe problem here -- I believe -- is that the module, which is\r\nresponsible for invoking the event, belongs to the root context\r\n(all modules are now \"booted\" in the root context.) So the root\r\nactivity context is invoking the event listener, but the listener's\r\nandroid context is not the root activity.
\r\nTo see a failcase, create a new Titanium project and make this\r\nits app.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\nwin.add( Ti.UI.createLabel({\r\n text: 'This is a lightweight window',\r\n left: 5, right: 5, top: 5, height: 40,\r\n color: 'black'\r\n}) );\r\n\r\nTi.App.addEventListener('test1', function(){\r\n alert('This is an alert');\r\n});\r\n\r\nvar btnTest = Ti.UI.createButton({\r\n title: 'Test alert() from event listener',\r\n top: 50, left: 5, right: 5, height: 40\r\n});\r\nbtnTest.addEventListener('click', function() {\r\n Ti.App.fireEvent('test1', {});\r\n});\r\nwin.add(btnTest);\r\n\r\nvar btn = Ti.UI.createButton({\r\n title: 'Open heavy window',\r\n top: 95, left: 5, right: 5, height: 40\r\n});\r\nbtn.addEventListener('click', function() {\r\n Ti.UI.createWindow({\r\n url: 'win.js',\r\n backgroundColor: '#fff',\r\n fullscreen: false\r\n }).open();\r\n});\r\nwin.add(btn);\r\nwin.open();
\r\n
\r\nThen add a new file, win.js, and make this its contents:
\r\n\r\nvar win = Ti.UI.currentWindow;\r\nwin.add( Ti.UI.createLabel({\r\n text: 'This is a heavyweight window',\r\n left: 5, right: 5, top: 5, height: 40,\r\n color: 'black'\r\n}) );\r\nTi.App.addEventListener('test2', function(){\r\n alert('This is an alert');\r\n});\r\nvar btnTest = Ti.UI.createButton({\r\n title: 'Test alert() from event listener',\r\n top: 50, left: 5, right: 5, height: 40\r\n});\r\nbtnTest.addEventListener('click', function() {\r\n Ti.App.fireEvent('test2', {});\r\n});\r\nwin.add(btnTest);\r\n\r\nvar btn = Ti.UI.createButton({\r\n title: 'Close',\r\n top: 95, left: 5, right: 5, height: 40\r\n});\r\nbtn.addEventListener('click', function() {\r\n win.close();\r\n});\r\nwin.add(btn);
\r\n
\r\nRun the project and follow these steps:
\r\nAssigned to Don for milestoning.