Bug
Problem:
Titanium.Network.addEventListener does not fire after creating new tabgroup.
Reproducible steps:
1.Run the code below.
2.Without clicking on 'Log In' button please change the network status on your Android device - the Titanium.Network event should be fired
3.Click on the 'Log In' button, after that new tabgroup will be created.
4.Change network status on your Android device - the event is no longer fired.
Expected behavior
Customer wants that the Titanium.Network.addEventListener would be a global listener (that would appear only once in the code). That should be the correct behaviour.
Sample Code:
var tabGroup = Titanium.UI.createTabGroup();
var win0 = Titanium.UI.createWindow();
var btnLogin = Titanium.UI.createButton({
title:'Log In',
color:'Black',
left:50,
height:30,
right:50
});
win0.add(btnLogin);
var tab0 = Titanium.UI.createTab({
title:'Log In',
window:win0
});
tabGroup.addTab(tab0);
tabGroup.open();
function BuildTabGroup(ActiveTabIndex){
// create tab group
var tabGroup2 = Titanium.UI.createTabGroup();
var mainWin= Titanium.UI.createWindow();
var tab0 = Titanium.UI.createTab({
window:mainWin
});
tabGroup2.addTab(tab0);
tabGroup2.open();
}
if (!Titanium.Network.online) {
var noNetworkAlert = Titanium.UI.createAlertDialog({
title: 'Network Error',
message: "You do not appear to have network connectivity. You will need an internet connection to use this application.",
buttonNames: ['OK']
});
noNetworkAlert.show();
}
Titanium.Network.addEventListener('change', function(e){
var online = e.online;
if (online) {
alert("Network connection re-established. You are now using your " + Titanium.Network.networkTypeName + " internet connection.");
}
else {
alert("Your network connectivity has been lost. Check your device settings.");
}
});
btnLogin.addEventListener('click',function(){
var tbg = Titanium.UI.currentTabGroup;
tbg.close();
tbg = null;
BuildTabGroup(0);
});
HelpDesk.
APP-287557
Wonder when this will be resolved? Is there any other workaround than checking any x sec if Ti.Network.online has changed?
Tested on a Samsung Galaxy S2 with 2.1GA. First time I open the app, it gives me an alert. I change the network status of the device and press the log in button. It comes up with a runtime error saying "Uncaught TypeError: Cannot call method 'close' of undefined. Source: tag.close();" No network changed event seems to be firing.
Resolving this as per updated test results. We tested the issue with TISDK 3.2GA and we could not reproduce it.
Titanium.Network.addEventListener is working as expected. Verified the fix using: Device : Google Nexus 4, Android Version: 4.1.1 SDK: 3.2.3.v20140311115447 CLI version : 3.2.1 OS : MAC OSX 10.9 Alloy: 1.3.1 ACS: 1.0.14 npm:1.3.2 Appcelerator Studio, build: 3.2.2.201403061827 titanium-code-processor: 1.1.0 XCode : 5.1