[TIMOB-982] Ti.App.addEventListener('close') not working
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Medium |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2011-04-17T01:54:52.000+0000 |
Affected Version/s | n/a |
Fix Version/s | Release 1.4.0 |
Components | iOS |
Labels | n/a |
Reporter | Nolan Wright |
Assignee | Blain Hamon |
Created | 2011-04-15T02:40:42.000+0000 |
Updated | 2011-04-17T01:54:52.000+0000 |
Description
code:
// this sets the background color of the master UIView (when there are no windows/tab groups on it) Titanium.UI.setBackgroundColor('#000');
// create tab group var tabGroup = Titanium.UI.createTabGroup();
Titanium.App.addEventListener('close',function(e)
{
alert("The application is being shutdown");
});
// // create base UI tab and root window // var win1 =
Titanium.UI.createWindow({
title:'Tab 1',
backgroundColor:'#fff',
barColor:'#005298'
});
var tab1 = Titanium.UI.createTab({
icon:'KS_nav_views.png',
title:'Tab 1',
window:win1
});
var navbar = Titanium.UI.createTabbedBar({
labels:["A", "B"],
style:Titanium.UI.iPhone.SystemButtonStyle.BAR,
backgroundColor:"#005298"
});
win1.setTitleControl(navbar);
var scrollView = Titanium.UI.createScrollView({
contentHeight: 'auto',
contentWidth:'auto',
top:0,
showVerticalScrollIndicator:true,
showHorizontalScrollIndicator:true
});
var view = Titanium.UI.createView({
width:300,
height:100,
top:20,
borderRadius:5,
backgroundGradient:{
type:'linear',
colors:[{color:'#005298',position:0.0},
{color:'#001d36',position:1.0}]
}
});
scrollView.add(view);
win1.add(scrollView);
// // add tabs // tabGroup.addTab(tab1);
// open tab group tabGroup.open();
This is a little misleading: The callback happens, but only after the program has suspended, which means that nothing is going to get logged. Seems like this will mostly end up being a documentation issue, provided that I can confirm that the stuff in the callback is actually happening (probably via a contacts or iPod test app).
Once this is taken care of there will need to be some additional infrastructure for 4.0's pause/resume.
Okay, much worse than I thought. There's a race between Titanium and the OS to see when resources get freed up: The system wants to release them immediately, and Titanium wants to try and finish everything up. 4.0 allows for the application to demand additional time to finish tasks in the background, but allowing compilation for 3.1.x (and iPad) means that app event support wouldn't work on these systems.
Investigating further.
Just so it doesn't slip through the cracks - this is also an issue on Android :)
Tag team coding. Swapping with Steve.
(from [f6e6787856b1faf7e7b71cd577b775544b25d0ee]) When closing, the app now sends the close event before the rest of the shutdown, and waits for the function to be processed before exiting. Note that it does mean if the javascript takes too long, the app will be force quit like the iPhone OS would any other app. Closes #982 http://github.com/appcelerator/titanium_mobile/commit/f6e6787856b1faf7e7b71cd577b775544b25d0ee"> http://github.com/appcelerator/titanium_mobile/commit/f6e6787856b1f...