Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-2990] Android: Window / Activity lifecycle events don't fire

GitHub Issuen/a
TypeBug
PriorityMedium
StatusClosed
ResolutionFixed
Resolution Date2011-04-17T02:00:37.000+0000
Affected Version/sn/a
Fix Version/sRelease 1.6.0 M08
ComponentsAndroid
Labelsactivity, android, defect, lifecycle, release-1.6.0, reported-1.6.0
ReporterMarshall Culpepper
AssigneeMarshall Culpepper
Created2011-04-15T03:34:15.000+0000
Updated2011-04-17T02:00:37.000+0000

Description

Our current activity lifecycle events aren't being fired for activities created from a heavy weight Ti.UI.Window. JS Activities seem to work because their lifecycle seems to be the right order, specifically:


// pseudo code
public void onCreate() {
  createLayout();
  initCurrentActivity(this);
  runScript();
  fireEvent("create");
}

The heavy weight window lifecycle however looks more like:


// pseudo code
public TiUIWindow() {
  startActivity();
}
public void onActivityCreated() {
  // script isn't even executed until after onCreate()
  initCurrentActivity(this);
  runScript();
}

This is affecting a lot of our new sensor and sound API refactors that depend on pause/resume to work for correct add/remove event listener behavior.

Comments

  1. martijn189 2011-04-15

    Is this really fixed?, i downloaded the Continuous Build of Feb 2 2011 15:24 ra02f7db3 but i still have this issue. what does "Release 1.6.0 M08" mean?

  2. Marshall Culpepper 2011-04-15

    (from [43ae52cacc38f22b4efa292d5ef27272560125ad]) initial refactor of TiRootActivity as a TiBaseActivity, implement better activity lifecycle support for all TiBaseActivities [#2990]
    https://github.com/appcelerator/titanium_mobile/commit/43ae52cacc38f22b4efa292d5ef27272560125ad"> https://github.com/appcelerator/titanium_mobile/commit/43ae52cacc38...

  3. Marshall Culpepper 2011-04-15

    (from [89ac3987ed38a4896f6147f4f416ccb4632f8332]) TiJSActivity and TiRootActivity now subclass a common TiLaunchActivity. "launch" activities have the distinction of being entry points into the application either via standard user launch, or from some other Intent. implemented a small internal message queue for launch activities so window.open() doesn't block the activity. Activities event listeners should now always receive their lifecycle events synchronously: create, restart, start, resume, pause, stop, destroy. [#2990 state:fixed-in-qa] https://github.com/appcelerator/titanium_mobile/commit/89ac3987ed38a4896f6147f4f416ccb4632f8332"> https://github.com/appcelerator/titanium_mobile/commit/89ac3987ed38...

  4. Marshall Culpepper 2011-04-15

    (from [76647275afd7304f48ea8535b55a3db9e1e1f666]) moved all async / blocking callbacks to a new message queue implementation that allows single loop iteration and provides better "dispatch while blocking" behavior, fixing the vast majority of our deadlock issues. Kitchensink is now running mostly well on top of these changes. Changed setTimeout/setInterval to use handler messages instead of timer threads for better consistency. Added an intermediary TiActivityWindows class between launched internal activities and TiUIWindow for better inline notification and reaction to Activity onCreate(). fixed the weird activity indicator as widget code in kitchensink for Android. [#2990] [#2924] https://github.com/appcelerator/titanium_mobile/commit/76647275afd7304f48ea8535b55a3db9e1e1f666"> https://github.com/appcelerator/titanium_mobile/commit/76647275afd7...

  5. Marshall Culpepper 2011-04-15

    (from [7996c46a2312321e35135cdc403e0ff87eafb62a]) several fixes for the new lifecycle support / message queue: async events are now fired only using Handler, as it's safe (and expected) for them to fire after the script is finished loading. TiVideoActivity now uses one less thread and doesn't block when it's handling creation arguments. new Handler based timers are now cancelling correctly, and activity indicators no longer use two separate async messages for displaying (only one is needed to sync w/ main thread). fixed a bug where changing the title of a TiUIWindow always changed it for the previous window. [#2990] https://github.com/appcelerator/titanium_mobile/commit/7996c46a2312321e35135cdc403e0ff87eafb62a"> https://github.com/appcelerator/titanium_mobile/commit/7996c46a2312...

  6. Marshall Culpepper 2011-04-15

    (from [2649bb83a437f122f97c4e96671ece9b04abfae0]) retrieve the activity's current proxy if it was already created before querying a non-Activity window. [#2990] https://github.com/appcelerator/titanium_mobile/commit/2649bb83a437f122f97c4e96671ece9b04abfae0"> https://github.com/appcelerator/titanium_mobile/commit/2649bb83a437...

  7. Marshall Culpepper 2011-04-15

    This was my test case, it has instructions in the label

       
       var win = Ti.UI.createWindow({
           backgroundColor: "white",
           layout: "vertical"
       });
       var activity = Ti.Android.currentActivity;
       
       var instructions = Ti.UI.createLabel({
           text: "initial launch should fire create, start, resume\npressing \"home\" should fire pause, stop\nrelaunching should fire restart, start, resume. pressing \"back\" should fire pause, stop, destroy\ncheck log for destroy event"
       });
       win.add(instructions);
       
       var events = ["create", "restart", "start", "resume", "pause", "stop", "destroy"];
       var rows = {};
       var data = [];
       events.forEach(function(event) {
           if (event != "destroy") {
               // we won't be able to see destroy events in UI, check the log
               rows[event] = Ti.UI.createTableViewRow({
                   title: event + " fired : false",
                   color: "red",
                   font: { fontSize: 16 }
               });
               data.push(rows[event]);
           }
           Ti.API.debug("adding activity " + event + " listener");
           activity.addEventListener(event, function(e) {
               Ti.API.debug("[LH-2990] event fired: " + event);
               if (event != "destroy") {
                   rows[event].color = "green";
                   rows[event].title = event + " fired: true"
               }
           });
       });
       
       var table = Ti.UI.createTableView({
           data: data,
           top: 5, bottom: 0, left: 0, right: 0
       });
       win.add(table);
       
       win.open();
       
  8. Thomas Huelbert 2011-04-15

    [INFO] Titanium SDK version: 1.6.0 (02/08/11 20:55 bd9d124...) galaxy tab (2.2.2) G1 (1.6) Nexus S (2.3) sim 2.1

JSON Source