{ "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\n

The 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\n

To 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\n

Then 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\n

Run the project and follow these steps:

\r\n
{html}", "attachment": [], "flagged": false, "summary": "Android: event listeners on modules and from heavyweight windows cannot show alerts.", "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": "129783", "author": { "name": "billdawson", "key": "billdawson", "displayName": "Bill Dawson", "active": true, "timeZone": "Europe/Berlin" }, "body": "{html}

Assigned to Don for milestoning.

{html}", "updateAuthor": { "name": "billdawson", "key": "billdawson", "displayName": "Bill Dawson", "active": true, "timeZone": "Europe/Berlin" }, "created": "2011-04-15T03:33:56.000+0000", "updated": "2011-04-15T03:33:56.000+0000" }, { "id": "216902", "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 unable to reproduce. However, you get multiple alerts once you open/exit the heavyweight window. Related to TIMOB-2969. ", "updateAuthor": { "name": "jyounus", "key": "jyounus", "displayName": "Junaid Younus", "active": true, "timeZone": "Europe/London" }, "created": "2012-08-29T14:51:07.000+0000", "updated": "2012-08-29T14:51:07.000+0000" }, { "id": "425040", "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:21.000+0000", "updated": "2017-07-28T19:30:21.000+0000" } ], "maxResults": 3, "total": 3, "startAt": 0 } } }