{ "id": "172590", "key": "TIMOB-26542", "fields": { "issuetype": { "id": "4", "description": "An improvement or enhancement to an existing feature or task.", "name": "Improvement", "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": [ { "id": "20832", "name": "Release 8.3.0", "archived": false, "released": true, "releaseDate": "2019-11-25" } ], "resolution": { "id": "1", "description": "A fix for this issue is checked into the tree and tested.", "name": "Fixed" }, "resolutiondate": "2019-09-10T22:17:58.000+0000", "created": "2018-11-10T03:04:51.000+0000", "priority": { "name": "Low", "id": "4" }, "labels": [ "android", "app", "close", "event", "parity" ], "versions": [], "issuelinks": [], "assignee": { "name": "jquick", "key": "jquick", "displayName": "Joshua Quick", "active": true, "timeZone": "America/Los_Angeles" }, "updated": "2019-10-03T10:51:59.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": "*Summary:*\r\nThe {{Ti.App}} module supports a \"close\" event that is currently only supported by iOS. This event gets fired just before the application get terminated by the operating system.\r\nhttps://docs.appcelerator.com/platform/latest/#!/api/Titanium.App-event-close\r\n\r\nWe should add support on Android for parity. However, the \"close\" event should be fired just before Titanium's JavaScript runtime gets terminated instead. The reason is because pressing the back button on the root window will terminate Titanium's JavaScript runtime (which is okay) but the Android application process will still be alive in the background (this keeps its notifications alive in the status bar). Tapping the app icon again will create a new JavaScript runtime and re-execute the \"app.js\" while re-using the same application process. This is the normal native Android behavior.\r\n\r\nThis feature may be useful to \"hyperloop\" developers who need to do cleanup operations upon exit.\r\n\r\n*Code Example:*\r\n{code:javascript}\r\nTi.App.addEventListener(\"close\", function() {\r\n\tTi.API.info(\"### App 'close' event was fired.\");\r\n});\r\nTi.UI.createWindow().open();\r\n{code}\r\n\r\n*Recommended Solution:*\r\nRemove the existing \"close\" firing event code in the Java {{TiRootActivity.onDestroy()}} method. It doesn't work because the JavaScript runtime has already been terminated by this point. It's too late.\r\n[TiRootActivity.java|https://github.com/appcelerator/titanium_mobile/blob/master/android/titanium/src/java/org/appcelerator/titanium/TiRootActivity.java]\r\n\r\nInstead, use the new Java {{KrollRuntime.OnDisposingListener}} that we've added to Titanium 8.0.0. This listener will be called just before the JavaScript runtime gets terminated/disposed.\r\n[KrollRuntime.java|https://github.com/appcelerator/titanium_mobile/blob/master/android/runtime/common/src/java/org/appcelerator/kroll/KrollRuntime.java]\r\n", "attachment": [], "flagged": false, "summary": "Android: Add Ti.App \"close\" event support", "creator": { "name": "jquick", "key": "jquick", "displayName": "Joshua Quick", "active": true, "timeZone": "America/Los_Angeles" }, "subtasks": [], "reporter": { "name": "jquick", "key": "jquick", "displayName": "Joshua Quick", "active": true, "timeZone": "America/Los_Angeles" }, "environment": null, "comment": { "comments": [ { "id": "445485", "author": { "name": "jquick", "key": "jquick", "displayName": "Joshua Quick", "active": true, "timeZone": "America/Los_Angeles" }, "body": "PR (master): https://github.com/appcelerator/titanium_mobile/pull/10637", "updateAuthor": { "name": "jquick", "key": "jquick", "displayName": "Joshua Quick", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2019-01-19T02:34:15.000+0000", "updated": "2019-01-19T02:34:15.000+0000" }, { "id": "445748", "author": { "name": "kmahalingam", "key": "kmahalingam", "displayName": "Keerthi Mahalingam", "active": false, "timeZone": "America/Los_Angeles" }, "body": "FR Passed. Waiting for CR to merge.", "updateAuthor": { "name": "kmahalingam", "key": "kmahalingam", "displayName": "Keerthi Mahalingam", "active": false, "timeZone": "America/Los_Angeles" }, "created": "2019-01-29T18:25:48.000+0000", "updated": "2019-01-29T18:25:48.000+0000" }, { "id": "451804", "author": { "name": "eboateng", "key": "eboateng", "displayName": "Ebenezer Boateng", "active": true, "timeZone": "America/Los_Angeles" }, "body": "Improvement verified in SDK version 8.3.0.v20191002165629", "updateAuthor": { "name": "eboateng", "key": "eboateng", "displayName": "Ebenezer Boateng", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2019-10-03T10:51:45.000+0000", "updated": "2019-10-03T10:51:45.000+0000" } ], "maxResults": 3, "total": 3, "startAt": 0 } } }