Problem
At the very least, focus doesn't fire:
1. When the tab is opened
2. When returning to a window from a child activity
This used to work in 1.5.x, but seems to have broken in 1.6.x.
Note, test case below demonstrates problem still exists with CI Build Titanium 1.9.0 (2012/01/16 11:16 366b32d) with v8 runtime.
Test case
Test case adapted from Pedro's code in the comments below.
var tabGroup = Ti.UI.createTabGroup();
var win1 = Ti.UI.createWindow({
url:'win1.js'
});
var tab1 = Ti.UI.createTab({
title:'Tab 1',
window:win1
});
var win2 = Ti.UI.createWindow({
title:'Tab 2',
backgroundColor:'#fff'
});
var tab2 = Ti.UI.createTab({
title:'Tab 2',
window:win2
});
tabGroup.addTab(tab1);
tabGroup.addTab(tab2);
tab1.addEventListener('focus', function(e){
Ti.API.info('-------------> tab1 focus event fired! - ' + e); // not fired
});
tab2.addEventListener('focus', function(e){
Ti.API.info('-------------> tab2 focus event fired! - ' + e); // not fired
});
win2.addEventListener('focus', function(e){
Ti.API.info('-------------> win2 focus event fired! - ' + e); // fired once
});
tabGroup.open();
var win = Ti.UI.currentWindow;
win.addEventListener('focus', function(e){
Ti.API.info('-------------> win1 focus event fired! - ' + e); // fired once
});
Logs
1945 AndroidRuntime D >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<<
1945 AndroidRuntime D CheckJNI is ON
1945 AndroidRuntime D --- registering native functions ---
60 ActivityManager I Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.appcelerator.testing10/.Testing10Activity }
60 ActivityManager I Start proc com.appcelerator.testing10 for activity com.appcelerator.testing10/.Testing10Activity: pid=1951 uid=10044 gids={1015, 3003}
1945 AndroidRuntime D Shutting down VM
1945 AndroidRuntime I NOTE: attach of thread 'Binder Thread #3' failed
1951 TiApplication I (main) [0,0] checkpoint, app created.
1951 TiApplication I (main) [639,639] Titanium 1.9.0 (2012/01/16 11:16 366b32d)
1951 TiFastDev D (main) [416,1055] Enabling Fastdev on port 49986
1951 TiFastDev D (main) [14,1069] sent tokens successfully
1951 TiFastDev D (main) [1,1070] Fastdev session handshake succesful.
1951 TiApplication I (main) [12,1082] Titanium Javascript runtime: v8
1951 TiApplication W (main) [62,1144] activity stack is emtpy, unable to get current activity
1951 TiRootActivity I (main) [0,0] checkpoint, on root activity create, savedInstanceState: null
1951 TiApplication W (main) [239,239] activity stack is emtpy, unable to get current activity
1951 TiApplication W (main) [2,241] activity stack is emtpy, unable to get current activity
1951 TiApplication W (main) [13,254] activity stack is emtpy, unable to get current activity
1951 TiApplication E (KrollRuntimeThread) [1135,1389] APP PROXY: ti.modules.titanium.app.AppModule@44eb2230
1951 TiAssetHelper D Fetching "app.js" with Fastdev...
60 ActivityManager I Starting activity: Intent { cmp=com.appcelerator.testing10/ti.modules.titanium.ui.TiTabActivity (has extras) }
1951 TiRootActivity I (main) [0,0] checkpoint, on root activity resume. activity = com.appcelerator.testing10.Testing10Activity@44e89700
1951 TiTabActivity W (main) [244,244] Notifying TiTabGroup, activity is created
1951 TiDrawableReference W (main) [100,344] Could not open stream to get bitmap
1951 Window D Loading window with URL: win1.js
1951 Module D Loading module: win1 -> Resources/win1.js
1951 TiAssetHelper D Fetching "win1.js" with Fastdev...
1951 TiAPI I -------------> win1 focus event fired! - [object Object]
1951 TiDrawableReference W (main) [290,634] Could not open stream to get bitmap
60 ActivityManager I Displayed activity com.appcelerator.testing10/ti.modules.titanium.ui.TiTabActivity: 707 ms (total 105095 ms)
1951 TiAPI I -------------> win2 focus event fired! - [object Object]
1951 TiAnalyticsSvc W (Thread-12) [27687,28321] Analytics Service Started
1951 TiAnalyticsSvc I (Thread-12) [66,28387] Sending 1 analytics events.
1951 TiAnalyticsSvc W (Thread-12) [1129,29516] Stopping Analytics Service
60 torageMonitorService I Memory available. Cancelling notification
167 GoogleLoginService D onBind: Intent { act=android.accounts.AccountAuthenticator cmp=com.google.android.gsf/.loginservice.GoogleLoginService }
Assigning to Don for triage.
There is a http://developer.appcelerator.com/helpdesk/view/76548">helpdesk ticket that encounter this bug. I have made a simple app:
app.js
win.js
The focus event is not firing.
Ti. SDK 1.6.1
Android APIs 2.2
I have come up with a simpler reproduction.
Sample Code
The following will show an alert dialog the first time to load each tab. But subsequent focuses of a particular tab will not raise the event. Run the same code on iOS, and you will see that the focus event fires whenever you switch tabs. Drop this in an app.js; nothing more is required.Associated Helpdesk Ticket
http://appc.me/c/APP-141651Is there any news on this issue? This is really a show stopper for me, and with all respect, it has been over two months. I can't see any other way to update my windows 'on focus' on Android (unless I have to use some really nasty hacks which I refuse), where as on iOS everything works fine.
This isn't just broken on Phones - it happens in the emulator and phones.
This has been fixed in Continuous Build - Titanium 1.9.0 (2012/01/16 11:16 366b32d). Confirmed with test case in TIMOB-7200.
Still an issue, confirmed with master at 62a55c71 (today). In both android and iphone, when the app loads, the first tab's window's focus event fires (as expected.) Then you click on the second tab and its window's focus event fires (as expected.) But then, in android, when you click back on the first tab, its window's focus event does _not_ fire. Same when you then click back on the second tab. In other words, in our android implementation you get one shot at the focus event with each tab. In our iPhone implementation, it keeps working every time you change tabs. I think it's clear that our iPhone behavior is the correct behavior. So this item needs to stay opened.
Sample code to test both focus and blur events.
Test Case:
Closing bug. Verified fix on: SDK build: 1.9.0.v20120203160134 Runtime: V8, Rhino Titanium Studio, build: 1.0.8.201201262211 Devices: Droid 1 (2.2.3)
Anvil testcase PR https://github.com/appcelerator/titanium_mobile/pull/5074