Uploaded image for project: 'Titanium SDK/CLI'
  1. Titanium SDK/CLI
  2. TIMOB-26542

Android: Add Ti.App "close" event support

    Details

      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

      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

        Attachments

          Activity

            People

            • Assignee:
              jquick Joshua Quick
              Reporter:
              jquick Joshua Quick
              Reviewer:
              Gary Mathews
              Tester:
              Ebenezer Boateng
            • Watchers:
              5 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Backbone Issue Sync

                • Backbone Issue Sync is enabled for your project, but we do not have any synchronization info for this issue.

                  Git Source Code