Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-5041] Android: Activity related events fire only once for tabgroup activity

GitHub Issuen/a
TypeBug
PriorityMedium
StatusClosed
ResolutionInvalid
Resolution Date2011-09-12T13:36:25.000+0000
Affected Version/sRelease 1.7.2
Fix Version/sn/a
ComponentsAndroid
Labelsandroid, enterprise
ReporterAnirudh Nagesh
AssigneeDon Thorp
Created2011-08-17T18:07:23.000+0000
Updated2017-03-23T21:37:29.000+0000

Description

The activity related events fire only once on tabgroup activity, but works fine with a heavyweight window. The Sample code is below.
Titanium.UI.setBackgroundColor('#000');

// create tab group
var tabGroup = Titanium.UI.createTabGroup();


//
// create base UI tab and root window
//
var win1 = Titanium.UI.createWindow({  
    title:'Tab 1',
    backgroundColor:'#fff'
});
var tab1 = Titanium.UI.createTab({  
    icon:'KS_nav_views.png',
    title:'Tab 1',
    window:win1
});

var label1 = Titanium.UI.createLabel({
	color:'#999',
	text:'I am Window 1',
	font:{fontSize:20,fontFamily:'Helvetica Neue'},
	textAlign:'center',
	width:'auto'
});

win1.add(label1);

//
// create controls tab and root window
//
var win2 = Titanium.UI.createWindow({  
    title:'Tab 2',
    backgroundColor:'#fff'
});
var tab2 = Titanium.UI.createTab({  
    icon:'KS_nav_ui.png',
    title:'Tab 2',
    window:win2
});

var label2 = Titanium.UI.createLabel({
	color:'#999',
	text:'I am Window 2',
	font:{fontSize:20,fontFamily:'Helvetica Neue'},
	textAlign:'center',
	width:'auto'
});

win2.add(label2);



//
//  add tabs
//
tabGroup.addTab(tab1);  
tabGroup.addTab(tab2);  


// open tab group
tabGroup.open();

Ti.Android.currentActivity.addEventListener('pause', function(e){
	Ti.API.info('changeState App is pausing');
});

Ti.Android.currentActivity.addEventListener('resume', function(e){
	Ti.API.info('changeState App is resuming');
});

Associated Hepdesk ticket:

appc.me/c/APP-834283

Comments

  1. Dawson Toth 2011-08-29

    Check out the workaround on [TIMOB-4121] for an explanation of how to get around what you are seeing.
  2. Moshe Marciano 2011-08-30

    The example in that ticket relies on multi-context application (url parameter in the createWindow call), we have a big app that suffered major stability issues until we were advised by you guys to convert it to a single-context app - that helped a lot, but set us back weeks behind our schedule. we cannot convert it back to multi-context because we don't have the time and it will bring instability back to the app. we need another workaround even if it is only temporary and even if it means a private fork of the framework...we need to ship the product ASAP.
  3. Moshe Marciano 2011-08-30

    BTW, all we need is to repsond to when the user presses the HOME key and send the app to the background...we need to cleanup and also when the app is resumed, we need to reinitiate. We don't need control per tab...right now we get a single event and further pause/resumed are not triggered.
  4. Pedro Enrique 2011-09-12

    The activity is in relationship with the window. This code works as expected: (assuming this is a single context application)

    Code:

       var W = {};
       W.Window = function(currentTab){
       	
       	var win = Ti.UI.createWindow({
       		fullscreen:false,
       		backgroundColor:"#"+((1<<24)*Math.random()|0).toString(16)
       	});
       	var btn = Ti.UI.createButton({
       		title:'click',
       		width:200,
       		height:50
       	});
       	win.add(btn);
       	
       	btn.addEventListener('click', function(){
       		currentTab.open(W.Window(currentTab));
       	});
       	
       	win.addEventListener('focus', function(){
       		Ti.API.info(' -=-=-=-=-=-=- focus -=-=-=-=-=-=- ');
       	});
       	win.activity.addEventListener('pause', function(){
       		Ti.API.info(' -=-=-=-=-=-=- pause -=-=-=-=-=-=- ');
       	});
       	win.activity.addEventListener('resume', function(){
       		Ti.API.info(' -=-=-=-=-=-=- resume -=-=-=-=-=-=- ');
       	});
       	return win;
       }
       
       W.TabGroup = function(){
       	var tabGroup = Ti.UI.createTabGroup();
       	var tab1 = Ti.UI.createTab({
       		title:'win1'
       	});
       	tab1.window = W.Window(tab1);
       	var tab2 = Ti.UI.createTab({
       		title:'win2'
       	});
       	tab2.window = W.Window(tab2);
       	tabGroup.addTab(tab1);
       	tabGroup.addTab(tab2);
       	return tabGroup;
       }
       
       W.TabGroup().open();
       

    Conclusion:

    - Make the windows "fullscreen: false" - And set the event listener to the window's activity
  5. Pedro Enrique 2011-09-12

    Working sample code provided. This is not a bug.
  6. Joe Falcone 2012-05-24

    This example only works if the window is part of a tabGroup. Otherwise, if you have a heavyweight window that is not part of a tabGroup, if you try to do something with the activity of the heavyweight window, such as win.activity.addEventListener('pause', function () { Ti.API.info('pause') }); you get "Uncaught TypeError: Object # has no method 'addEventListener' If you need an example, just remove the tabGroup from the above example. So for us that do not use tabGroup's, what should we do to get access to pause & resume events.
  7. Joe Falcone 2012-05-24

  8. Lee Morris 2017-03-23

    Closing ticket as invalid with reference to the previous comments.
  9. JSON Source