Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-26542] Android: Add Ti.App "close" event support

GitHub Issuen/a
TypeImprovement
PriorityLow
StatusClosed
ResolutionFixed
Resolution Date2019-09-10T22:17:58.000+0000
Affected Version/sn/a
Fix Version/sRelease 8.3.0
ComponentsAndroid
Labelsandroid, app, close, event, parity
ReporterJoshua Quick
AssigneeJoshua Quick
Created2018-11-10T03:04:51.000+0000
Updated2019-10-03T10:51:59.000+0000

Description

*Summary:* The 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. https://docs.appcelerator.com/platform/latest/#!/api/Titanium.App-event-close We 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. This feature may be useful to "hyperloop" developers who need to do cleanup operations upon exit. *Code Example:*
Ti.App.addEventListener("close", function() {
	Ti.API.info("### App 'close' event was fired.");
});
Ti.UI.createWindow().open();
*Recommended Solution:* Remove 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. [TiRootActivity.java](https://github.com/appcelerator/titanium_mobile/blob/master/android/titanium/src/java/org/appcelerator/titanium/TiRootActivity.java) Instead, 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. [KrollRuntime.java](https://github.com/appcelerator/titanium_mobile/blob/master/android/runtime/common/src/java/org/appcelerator/kroll/KrollRuntime.java)

Comments

  1. Joshua Quick 2019-01-19

    PR (master): https://github.com/appcelerator/titanium_mobile/pull/10637
  2. Keerthi Mahalingam 2019-01-29

    FR Passed. Waiting for CR to merge.
  3. Ebenezer Boateng 2019-10-03

    Improvement verified in SDK version 8.3.0.v20191002165629

JSON Source