Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-11673] Android: require breaks the network change event listener

GitHub Issuen/a
TypeBug
PriorityLow
StatusClosed
ResolutionCannot Reproduce
Resolution Date2012-12-04T00:54:01.000+0000
Affected Version/sn/a
Fix Version/s2012 Sprint 25, 2012 Sprint 25 Core, 2012 Sprint 25 API
ComponentsAndroid
Labelsn/a
ReporterDavide Cassenti
AssigneePing Wang
Created2012-11-06T16:52:53.000+0000
Updated2017-03-27T20:37:23.000+0000

Description

Problem description

Whenever a require function is called, the network change event listener is broken.

Steps to reproduce

Create 3 files: app.js, win.js and view.js *app.js*
(function() {
    var Window = require('win');
	new Window().open();
})();
*win.js*
function ApplicationWindow() {
    var view = require('view'); // just requiring, we are not even invoking the function
    
    var self = Ti.UI.createWindow({
        backgroundColor:'#ffffff',
        navBarHidden:true,
        exitOnClose:true
    });
        
    return self;
}
module.exports = ApplicationWindow;
*view.js*
function SimpleView() {
    var view = Ti.UI.createView({
        backgroundColor:'red',
        width: 100,
        height: 100
    });
        
    return view;
}

module.exports = SimpleView;
Now, there are 3 scenarios; use this simple listener code:
Titanium.Network.addEventListener('change', function(e) {
    alert('Status changed:' + e.networkType);
});
1. add the network listener code in app.js or win.js: it will only be fired ONCE [BUG] 2. add the listener code in view.js: everything is ok 3. add the listener code in win.js and remove the require('view') from it: everything is ok

Comments

  1. Davide Cassenti 2012-11-12

    - I've tested back with 2.1.2, 2.1.1 and 2.1.0: same results. - I've tested with 2.0.2: the listener is not called even once. - However, testing with v3.0.0.20121026170116 seems to be working. Was this addressed in the release? Below a simpler test case: app.js
       (function() {
           Titanium.Network.addEventListener('change', function(e) {
               alert('Status changed:' + e.networkType);
           });
       
           var Window = require('win');
           new Window().open();
       })();
       
    win.js
       function ApplicationWindow() {
           var self = Ti.UI.createWindow({
               backgroundColor:'#ffffff',
               navBarHidden:true,
               exitOnClose:true
           });
                
           return self;
       }
       module.exports = ApplicationWindow;
       
  2. Ping Wang 2012-12-04

    Tested with latest master and 3_0_X. The two test cases both pass. Mark the ticket as Cannot Reproduce.
  3. Lee Morris 2017-03-27

    Closing ticket as I am unable to reproduce this issue with the following environment; Pixel (7.1) MacOS 10.11.6 (15G31) Studio 4.8.1.201612050850 Ti SDK 6.0.3 GA Appc NPM 4.2.8 Appc CLI 6.1.0 Ti CLI 5.0.11 Alloy 1.9.5 Arrow 1.10.1 Xcode 8.2 (8C38) Node v4.6.0 Java 1.7.0_80

JSON Source