Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-3139] Android: UI.Window - Window in tabgroup focus event does not fire

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2012-03-11T22:23:16.000+0000
Affected Version/sRelease 1.7.0
Fix Version/sSprint 2012-03, Release 2.0.0, Release 1.8.2
ComponentsAndroid
Labelsmodule_tabgroup, qe-testadded, regression
ReporterNathaniel McCallum
AssigneeHieu Pham
Created2011-04-15T03:37:51.000+0000
Updated2013-12-10T06:00:08.000+0000

Description

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 }

Comments

  1. Stephen Tramer 2011-04-15

    Assigning to Don for triage.

  2. Pedro Enrique 2011-04-15

    There is a http://developer.appcelerator.com/helpdesk/view/76548">helpdesk ticket that encounter this bug. I have made a simple app:

    app.js

       var tabGroup = Titanium.UI.createTabGroup();
       
       var win1 = Titanium.UI.createWindow({
           url:'win.js'
       });
       var tab1 = Titanium.UI.createTab({
           icon:'icon1.png',
           title:'Tab 1',
           window:win1
       });
       
       var win2 = Titanium.UI.createWindow({
           title:'Tab 2',
           backgroundColor:'#fff'
       });
       var tab2 = Titanium.UI.createTab({
           icon:'icon1.png',
           title:'Tab 2',
           window:win2
       });
       
       tabGroup.addTab(tab1);
       tabGroup.addTab(tab2);  
       
       tabGroup.open();
       

    win.js

       var win = Titanium.UI.currentWindow;
       
       win.addEventListener('focus', function(e){
           Ti.API.info(e);
       });
       

    The focus event is not firing.

    Ti. SDK 1.6.1
    Android APIs 2.2

  3. Dawson Toth 2011-05-18

    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.
       var tabGroup = Ti.UI.createTabGroup();
       
       var tab1 = Ti.UI.createTab({ title: 'Tab 1', window: Ti.UI.createWindow() });
       var tab2 = Ti.UI.createTab({ title: 'Tab 2', window: Ti.UI.createWindow() });
       
       tab1.window.addEventListener('focus', function() { alert('1 focused!'); });
       tab2.window.addEventListener('focus', function() { alert('2 focused!'); });
       
       tabGroup.addTab(tab1);
       tabGroup.addTab(tab2);
       
       tabGroup.open();
       
  4. Jon Alter 2011-06-16

    Associated Helpdesk Ticket

    http://appc.me/c/APP-141651
  5. Stefan Moonen 2011-08-26

    Is 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.
  6. Jeff Bonnes 2011-11-09

    This isn't just broken on Phones - it happens in the emulator and phones.
  7. Paul Dowsett 2012-01-16

    This has been fixed in Continuous Build - Titanium 1.9.0 (2012/01/16 11:16 366b32d). Confirmed with test case in TIMOB-7200.
  8. Bill Dawson 2012-01-24

    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.
  9. Ping Wang 2012-01-26

    Sample code to test both focus and blur events.
       var tabGroup = Ti.UI.createTabGroup();
       
       var win1 = Ti.UI.createWindow({
       	name: "win 1"
       });
       var tab1 = Ti.UI.createTab({
       	name: "Tab 1",
       	title:'Tab 1',
       	window:win1
       });
       
       var win2 = Ti.UI.createWindow({
       	name: "win 2",
       	title:'Tab 2',
       	backgroundColor:'#fff'
       });
       var tab2 = Ti.UI.createTab({
       	name: "Tab 2",
       	title:'Tab 2',
       	window:win2
       });
       
       tabGroup.addTab(tab1);
       tabGroup.addTab(tab2);
       
       tab1.addEventListener('focus', function(e){
       	Ti.API.info('-------------> tab1 focus event fired! - ' + e.source.name);
       });
       tab2.addEventListener('focus', function(e){
       	Ti.API.info('-------------> tab2 focus event fired! - ' + e.source.name);
       });
       win1.addEventListener('focus', function(e){
       	Ti.API.info('-------------> win1 focus event fired! - ' + e.source.name);
       });
       win2.addEventListener('focus', function(e){
       	Ti.API.info('-------------> win2 focus event fired! - ' + e.source.name);
       });
       
       tab1.addEventListener('blur', function(e){
       	Ti.API.info('**************> tab1 blur event fired! - ' + e.source.name);
       });
       tab2.addEventListener('blur', function(e){
       	Ti.API.info('**************> tab2 blur event fired! - ' + e.source.name);
       });
       win1.addEventListener('blur', function(e){
       	Ti.API.info('**************> win1 blur event fired! - ' + e.source.name);
       });
       win2.addEventListener('blur', function(e){
       	Ti.API.info('**************> win2 blur event fired! - ' + e.source.name);
       });
       
       tabGroup.open();
       
  10. Hieu Pham 2012-01-30

    Test Case:
        var tabGroup = Ti.UI.createTabGroup();
        
        var win1 = Ti.UI.createWindow({
        	name: "win 1"
        });
        var tab1 = Ti.UI.createTab({
        	name: "Tab 1",
        	title:'Tab 1',
        	window:win1
        });
        
        var win2 = Ti.UI.createWindow({
        	name: "win 2",
        	title:'Tab 2',
        	backgroundColor:'#fff'
        });
        var tab2 = Ti.UI.createTab({
        	name: "Tab 2",
        	title:'Tab 2',
        	window:win2
        });
        
        tabGroup.addTab(tab1);
        tabGroup.addTab(tab2);
        
        tabGroup.addEventListener('focus', function(e){
        	Ti.API.info('-------------> tabGroup focus event fired! - ' + e.source.name);
        });
        tab1.addEventListener('focus', function(e){
        	Ti.API.info('-------------> tab1 focus event fired! - ' + e.source.name);
        });
        tab2.addEventListener('focus', function(e){
        	Ti.API.info('-------------> tab2 focus event fired! - ' + e.source.name);
        });
        win1.addEventListener('focus', function(e){
        	Ti.API.info('-------------> win1 focus event fired! - ' + e.source.name);
        });
        win2.addEventListener('focus', function(e){
        	Ti.API.info('-------------> win2 focus event fired! - ' + e.source.name);
        });
        
        tab1.addEventListener('blur', function(e){
        	Ti.API.info('**************> tab1 blur event fired! - ' + e.source.name);
        });
        tab2.addEventListener('blur', function(e){
        	Ti.API.info('**************> tab2 blur event fired! - ' + e.source.name);
        });
        win1.addEventListener('blur', function(e){
        	Ti.API.info('**************> win1 blur event fired! - ' + e.source.name);
        });
        win2.addEventListener('blur', function(e){
        	Ti.API.info('**************> win2 blur event fired! - ' + e.source.name);
        });
        
        tabGroup.open();
        
  11. Wilson Luu 2012-02-03

    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)
  12. Shameer Jan 2013-12-10

    Anvil testcase PR https://github.com/appcelerator/titanium_mobile/pull/5074

JSON Source