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

Android: Activity callbacks onStop/onDestroy not invoked on main thread as of 7.5.0

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Medium
    • Resolution: Fixed
    • Affects Version/s: Release 7.5.0
    • Fix Version/s: Release 8.0.0
    • Component/s: Android
    • Environment:
    • Story Points:
      3
    • Sprint:
      2019 Sprint 5

      Description

      Summary:
      If "tiapp.xml" property "run-on-main-thread" is set to true, then the activity's onStop and onDestroy callbacks are not invoked upon app exit. This is a regression as of 7.5.0.

      Steps to reproduce:

      1. Set "tiapp.xml" property "run-on-main-thread" to true as shown below.
      2. Use the below "app.js" code.
      3. Build and run on Android.
      4. Wait for the app to launch.
      5. Notice in the log that "onStart()" and "onResume()" were successfully called.
      6. Back out of the app to exit.
      7. Notice in the log that "TopActivity.onStop()", "TopActivity.onDestroy()", and "RootActivity.onDesroy()" did not get called.

      tiapp.xml

      <?xml version="1.0" encoding="UTF-8"?>
      <ti:app xmlns:ti="http://ti.appcelerator.org">
      	<property name="run-on-main-thread" type="bool">true</property>
      </ti:app>
      

      app.js

      function addActivityListenersTo(activity, name) {
      	if (!activity) {
      		return;
      	}
      	if (!name) {
      		name = "Activity";
      	}
      	activity.onCreate = function() {
      		Ti.API.info("@@@ " + name + ".onCreate() called.");
      	};
      	activity.onRestart = function() {
      		Ti.API.info("@@@ " + name + ".onRestart() called.");
      	};
      	activity.onStart = function() {
      		Ti.API.info("@@@ " + name + ".onStart() called.");
      	};
      	activity.onResume = function() {
      		Ti.API.info("@@@ " + name + ".onResume() called.");
      	};
      	activity.onPause = function() {
      		Ti.API.info("@@@ " + name + ".onPause() called.");
      	};
      	activity.onStop = function() {
      		Ti.API.info("@@@ " + name + ".onStop() called.");
      	};
      	activity.onDestroy = function() {
      		Ti.API.info("@@@ " + name + ".onDestroy() called.");
      	};
      }
       
      addActivityListenersTo(Ti.Android.currentActivity, "RootActivity");
       
      var window = Ti.UI.createWindow();
      window.add(Ti.UI.createLabel({ text: "Activity Callback Test" }));
      window.addEventListener("open", function() {
      	Ti.API.info("@@@ Window 'open' event fired.");
      });
      addActivityListenersTo(window.activity, "TopActivity");
      window.open();
      

      Work-Around 1:
      If you are building with Titanium 7.5.x, then setting "run-on-main-thread" to false then the onStop() and onDestroy() callbacks will be successfully invoked.

      Work-Around 2:
      Add a listener to the Ti.UI.Window object's "close" event instead. This event is supported on both Android and iOS, making it a portable solution.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                jquick Joshua Quick
                Reporter:
                aislam Aminul Islam
                Reviewer:
                Gary Mathews
              • Watchers:
                7 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Backbone Issue Sync

                  • Titanium SDK/CLI <> Titanium Mobile
                    Synced with:
                    TIMOB-21054
                    Sync status:
                    PENDING
                    Last received:
                    Last sent:

                    Git Source Code