[TIMOB-2924] Android: Activity related events don't fire in app.js
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Medium |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2011-08-17T18:10:51.000+0000 |
Affected Version/s | n/a |
Fix Version/s | Release 1.6.0 M08 |
Components | Android |
Labels | android, defect, enterprise, release-1.6.0, reported-1.6.0, rplist |
Reporter | Dawson Toth |
Assignee | Don Thorp |
Created | 2011-04-15T03:33:02.000+0000 |
Updated | 2011-08-17T18:10:51.000+0000 |
Description
Problem
In the app.js, events bound to Ti.Android.currentActivity do not fire. Events include: create, start, pause, resume, stop, and destroy.
Workaround
Open a window with a URL set, and the nav bar hidden, modal true, or fullscreen true. In that JavaScript context, most of the events will fire. I was not able to get "create", "destroy", or "start" to fire (a separate issue, perhaps?).
Sample Code
The following code, placed alone in an app.js, demonstrates the problem. Launch the app, press the home button, and no events will fire. If you change the variable "forceHeavyweight" to true, app.js will open itself as a heavyweight window, and most of the events will fire.
(function() {
// force this into a heavyweight window?
var forceHeavyweight = false;
if (forceHeavyweight && Ti.UI.currentWindow == null) {
Ti.API.info('opening heavyweight window...');
Ti.UI.createWindow({ url: 'app.js', navBarHidden: true }).open();
return;
}
// add listeners
function addListener(event) {
Titanium.Android.currentActivity.addEventListener(event, function() {
Ti.API.info(event + ' fired!');
});
}
addListener('create');
addListener('start');
addListener('pause');
addListener('resume');
addListener('stop');
addListener('destroy');
// add some stuff to the window
var win = Titanium.UI.createWindow({
title: 'Window One',
backgroundColor: '#fff'
});
win.add(Titanium.UI.createLabel({
color: '#999',
text: 'I am a resumable app!',
font: { fontSize: 20, fontFamily: 'Helvetica Neue' },
textAlign: 'center',
width: 'auto'
}));
win.open();
})();
Trace Log from Normal App.js, not Heavyweight
[INFO] Deployed AndroidEvents ... Application should be running.
[TRACE] I/Log ( 335): (main) [0,0] checkpoint, app created.
[TRACE] I/TiApplication( 335): (main) [200,200] Titanium 1.6.0 (2011/01/19 13:14 ad18bd...)
[TRACE] D/TiApplication( 335): (main) [4,204] Application onCreate
[TRACE] E/TiPlatformHelper( 335): (main) [224,428] renaming ID
[TRACE] I/Log ( 335): (main) [0,0] checkpoint, on root activity create, savedInstanceState: null
[TRACE] E/TiRootActivity( 335): (main) [1,1] Instance Count: 0
[TRACE] D/dalvikvm( 335): GC_FOR_MALLOC freed 3437 objects / 335208 bytes in 88ms
[TRACE] D/TiApplication( 335): (main) [198,199] Analytics Event: type=ti.start
[TRACE] D/TiApplication( 335): event=ti.start
[TRACE] D/TiApplication( 335): timestamp=2011-01-24T22:55:35.121-0600
[TRACE] D/TiApplication( 335): mid=f6d0df25-fb8e-44d4-9d62-50a738bc66ef
[TRACE] D/TiApplication( 335): sid=fc76c8d3-0330-4a71-8e7f-960de640596e
[TRACE] D/TiApplication( 335): aguid=3240e29c-aedb-4d35-88c3-48632e990e49
[TRACE] D/TiApplication( 335): isJSON=true
[TRACE] D/TiApplication( 335): payload={"os":"sdk","tz":-360,"nettype":"MOBILE","deploytype":"development","app_version":"1.0","osver":"2.2","un":"android-build","version":"1.6.0"}
[TRACE] E/TiApplication( 335): (main) [263,462] APP PROXY: [Ti.App]
[TRACE] E/ROOT ( 335): (main) [366,828] Leaving TiRootActivity.onCreate
[TRACE] I/Log ( 335): (main) [0,0] checkpoint, on root activity resume. context = org.appcelerator.titanium.TiContext@44f4cec8
[TRACE] I/TiRootActivity( 335): (Thread-9) [8,8] eval app.js
[TRACE] D/KrollContext( 335): (kroll$1) [26,34] Running evaluated script: app://app.js
[TRACE] W/TiAnalyticsSvc( 335): (Thread-10) [82,116] Analytics Service Started
[TRACE] D/dalvikvm( 335): GC_FOR_MALLOC freed 5312 objects / 356272 bytes in 138ms
[TRACE] I/ActivityManager( 60): Displayed activity com.dawson.androidevents/.AndroideventsActivity: 4214 ms (total 4214 ms)
[TRACE] I/TiAnalyticsSvc( 335): (Thread-10) [1896,2012] Sending 1 analytics events.
[TRACE] D/dalvikvm( 335): GC_FOR_MALLOC freed 6016 objects / 367320 bytes in 81ms
[TRACE] D/dalvikvm( 335): GC_FOR_MALLOC freed 419 objects / 22432 bytes in 81ms
[TRACE] W/TiAnalyticsSvc( 335): (Thread-10) [1652,3664] Stopping Analytics Service
[TRACE] D/dalvikvm( 269): GC_EXPLICIT freed 948 objects / 54512 bytes in 72ms
[TRACE] D/dalvikvm( 277): GC_EXPLICIT freed 694 objects / 52368 bytes in 105ms
[TRACE] I/ActivityManager( 60): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.HOME] flg=0x10200000 cmp=com.android.launcher/com.android.launcher2.Launcher }
[TRACE] D/TiRootActivity( 335): (main) [143099,146763] root activity onPause, context = org.appcelerator.titanium.TiContext@44f4cec8
[TRACE] W/InputManagerService( 60): Ignoring hideSoftInput of: com.android.internal.view.IInputMethodClient$Stub$Proxy@45017aa8
[TRACE] I/ActivityManager( 60): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.HOME] flg=0x10200000 cmp=com.android.launcher/com.android.launcher2.Launcher }
[TRACE] W/InputManagerService( 60): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@44edca88
[TRACE] I/ActivityManager( 60): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.dawson.androidevents/.AndroideventsActivity bnds=[125,70][235,188] }
[TRACE] I/Log ( 335): (main) [0,0] checkpoint, on root activity resume. context = org.appcelerator.titanium.TiContext@44f4cec8
[TRACE] D/dalvikvm( 141): GC_EXPLICIT freed 1171 objects / 85352 bytes in 105ms
[TRACE] D/dalvikvm( 269): GC_EXPLICIT freed 374 objects / 19360 bytes in 68ms
Trace Log from Heavyweight Window
[TRACE] I/TiRootActivity( 710): (Thread-9) [12,12] eval app.js
[TRACE] D/KrollContext( 710): (kroll$1) [12,24] Running evaluated script: app://app.js
[TRACE] W/TiAnalyticsSvc( 710): (Thread-10) [125,149] Analytics Service Started
[INFO] [234,383] opening heavyweight window...
[TRACE] D/dalvikvm( 710): GC_FOR_MALLOC freed 5313 objects / 357472 bytes in 88ms
[TRACE] I/ActivityManager( 60): Displayed activity com.dawson.androidevents/.AndroideventsActivity: 5145 ms (total 5145 ms)
[TRACE] I/ActivityManager( 60): Starting activity: Intent { cmp=com.dawson.androidevents/org.appcelerator.titanium.TiActivity (has extras) }
[TRACE] D/TiRootActivity( 710): (main) [1502,1885] root activity onPause, context = org.appcelerator.titanium.TiContext@44facea0
[TRACE] D/qemud ( 38): fdhandler_accept_event: accepting on fd 10
[TRACE] D/qemud ( 38): created client 0x17018 listening on fd 15
[TRACE] D/qemud ( 38): client_fd_receive: attempting registration for service 'sensors'
[TRACE] D/qemud ( 38): client_fd_receive: -> received channel id 10
[TRACE] D/qemud ( 38): client_registration: registration succeeded for client 10
[TRACE] D/qemud ( 38): fdhandler_event: disconnect on fd 15
[TRACE] I/ActivityManager( 60): Displayed activity com.dawson.androidevents/org.appcelerator.titanium.TiActivity: 572 ms (total 572 ms)
[TRACE] D/KrollContext( 710): (kroll$2) [745,2630] Running evaluated script: app://app.js
[TRACE] I/TiAnalyticsSvc( 710): (Thread-10) [352,2982] Sending 1 analytics events.
[TRACE] D/dalvikvm( 710): GC_FOR_MALLOC freed 5577 objects / 367144 bytes in 74ms
[TRACE] D/dalvikvm( 710): GC_FOR_MALLOC freed 2802 objects / 149512 bytes in 69ms
[TRACE] W/TiAnalyticsSvc( 710): (Thread-10) [1672,4654] Stopping Analytics Service
[TRACE] I/ActivityManager( 60): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.HOME] flg=0x10200000 cmp=com.android.launcher/com.android.launcher2.Launcher }
[INFO] [2643,7297] pause fired!
[TRACE] W/InputManagerService( 60): Ignoring hideSoftInput of: com.android.internal.view.IInputMethodClient$Stub$Proxy@4504c618
[INFO] [534,7831] stop fired!
[TRACE] I/ActivityManager( 60): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.dawson.androidevents/.AndroideventsActivity bnds=[125,70][235,188] }
[INFO] [2510,10341] start fired!
[INFO] [2,10343] resume fired!
[TRACE] D/dalvikvm( 262): GC_EXPLICIT freed 105 objects / 5024 bytes in 59ms
[TRACE] D/dalvikvm( 126): GC_EXPLICIT freed 1164 objects / 64584 bytes in 82ms
[TRACE] D/dalvikvm( 585): GC_EXPLICIT freed 63 objects / 3600 bytes in 60ms
[TRACE] W/KeyCharacterMap( 710): No keyboard for id 0
[TRACE] W/KeyCharacterMap( 710): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
[INFO] [37330,47673] pause fired!
[TRACE] I/Log ( 710): (main) [0,0] checkpoint, on root activity resume. context = org.appcelerator.titanium.TiContext@44facea0
[INFO] [700,700] stop fired!
[TRACE] E/TiBaseActivity( 710): (main) [49,749] Layout cleanup.
[TRACE] D/TiRootActivity( 710): (main) [1872,2621] root activity onPause, context = org.appcelerator.titanium.TiContext@44facea0
[TRACE] D/TiRootActivity( 710): (main) [489,3110] root activity onDestroy, context = org.appcelerator.titanium.TiContext@44facea0
Associated Helpdesk Ticket
http://developer.appcelerator.com/helpdesk/view/68461">http://developer.appcelerator.com/helpdesk/view/68461
We found this on Friday but only verified it was a problem as well on Monday.
(from [4cdb1abb380f780b42ada014e05415402a8c335b]) [#2924] commiting my changes for the events being fired. Create is still missing. Marshall will resolve it along with 2990. https://github.com/appcelerator/titanium_mobile/commit/4cdb1abb380f780b42ada014e05415402a8c335b"> https://github.com/appcelerator/titanium_mobile/commit/4cdb1abb380f...
(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...
This was fixed with the lifecycle merge, also see the testcase attached to #2990
[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 using content from 2990
Marshall, the activity events don't seem to fire correctly when a tab group instead of a window is created in app.js. They will fire when the app is launched but the resume event will not fire if hitting the home button and then re-visiting the application:
var tabGroup = Titanium.UI.createTabGroup();
// main window var tmpWindow = Titanium.UI.createWindow({
{mkd-extraction-07b3db81cd896879545475daf0729a81}}); var tmpTab = Titanium.UI.createTab({
{mkd-extraction-21f199430d96bbfb8d3a23a1dfb069c9}});
tabGroup.addTab(tmpTab);
tabGroup.open();
Ti.Android.currentActivity.addEventListener('resume', function() {
{mkd-extraction-5e267346fda20e806190c88b15ea5349}});
Ti.Android.currentActivity.addEventListener('start', function() {
{mkd-extraction-04c48c1bcecf758460756ec5b3d21fcf}});
Ti.Android.currentActivity.addEventListener('pause', function() {
{mkd-extraction-ba7a59329baca5563699fa486f1834b4}});
The events fire only once on tabgroup activity, but works fine with a heavyweight window. Sample code:
Associated Hepdesk ticket:
appc.me/c/APP-834283