Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-1742] Android: Window in TabGroup loses event listeners

GitHub Issuen/a
TypeBug
PriorityMedium
StatusClosed
ResolutionFixed
Resolution Date2011-04-17T01:57:02.000+0000
Affected Version/sn/a
Fix Version/sRelease 1.6.0 M07
ComponentsAndroid
Labelsandroid, back, backbutton, button, close, defect, event, eventlistener, listener, release-1.6.0, tabGroup, tabgroup
ReporterLukasz
AssigneeJeff Haynie
Created2011-04-15T03:01:04.000+0000
Updated2011-04-17T01:57:02.000+0000

Description

This is similar problem to "Android: Window Closed with Back Button Won't Reopen" (https://appcelerator.lighthouseapp.com/projects/32238-titanium-mobile/tickets/1470">https://appcelerator.lighthouseapp.com/projects/32238-titanium-mobi...) but this happens if you use TabGroups instead Windows.

  1. Create two TabGroups with two windows.
  2. Attach a click event listener to the window in first TabGroup. This listener should open the second TabGroup.
  3. Open first TabGroup.
  4. Click on window and activate listener.
  5. Second TabGroup will open.
  6. Click Android back button, this will close second TabGroup.
  7. Click on window and activate listener. Nothing happens.

Testcase:

Titanium.UI.setBackgroundColor('#000');

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

// create base UI tab and root window
var win1 = Titanium.UI.createWindow({
    navBarHidden:false,
    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({
    navBarHidden:false,
    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
tabGroup1.addTab(tab1);
tabGroup1.addTab(tab2);

// open first tab group
tabGroup1.open();

// create base UI tab and root window
var win3 = Titanium.UI.createWindow({
    navBarHidden:false,
    title:'Tab 3',
    backgroundColor:'#fff'
});

var tab3 = Titanium.UI.createTab({
    icon:'KS_nav_views.png',
    title:'Tab 3',
    window:win3
});

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

win3.add(label3);

// create controls tab and root window
var win4 = Titanium.UI.createWindow({
    navBarHidden:false,
    title:'Tab 4',
    backgroundColor:'#fff'
});

var tab4 = Titanium.UI.createTab({
    icon:'KS_nav_ui.png',
    title:'Tab 4',
    window:win4
});

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

win4.add(label4);

//  add tabs
tabGroup2.addTab(tab3);
tabGroup2.addTab(tab4);

// attach click listener
win1.addEventListener('click', function(){
    // this will fire only once
    Ti.API.debug('fired click listener!');
    tabGroup2.open();
});

Trace:

// first click
[TRACE] E/TiUIView( 2146): (main) [8045,11705] TAP, TAP, TAP
[DEBUG] [28,11733] fired click listener!
[TRACE] I/TabGroupProxy( 2146): (main) [8,11741] handleOpen
[TRACE] I/ActivityManager( 61): Starting activity: Intent { cmp=com.AndroidBackButton/ti.modules.titanium.ui.TiTabActivity (has extras) }
[TRACE] D/PhoneWindow( 2146): couldn't save which view has focus because the focused view com.android.internal.policy.impl.PhoneWindow$DecorView@43e92980 has no id.
[TRACE] W/TiTabActivity( 2146): (main) [104,11845] Notifying TiTabGroup, activity is created
[TRACE] W/TiActivity( 2146): (main) [198,12043] Notifying TiUIWindow, activity is created
[TRACE] I/ActivityManager( 61): Displayed activity com.AndroidBackButton/ti.modules.titanium.ui.TiTabActivity: 417 ms (total 417 ms)
// back button
[TRACE] W/KeyCharacterMap( 2146): No keyboard for id 0
[TRACE] W/KeyCharacterMap( 2146): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
[TRACE] E/TiActivity( 2146): (main) [4082,16125] Layout cleanup.
// second click
[TRACE] E/TiUIView( 2146): (main) [2329,18454] TAP, TAP, TAP

EDITED:
Tested with mobilesdk-1.4.1-20100904221103-osx.zip

Attachments

FileDateSize
app.js2011-04-15T03:01:05.000+00003761

Comments

  1. Don Thorp 2011-04-15

    We need to check this with the new Kroll.

  2. Lukasz 2011-04-15

    Another similar ticket 'Android: event listeners in reopened window do not fire.' https://appcelerator.lighthouseapp.com/projects/32238-titanium-mobile/tickets/1767"> https://appcelerator.lighthouseapp.com/projects/32238-titanium-mobi...

  3. Lukasz 2011-04-15

    I've changed a little bit fail case. I've added a button to the first window. If you open and close (with back button) the second tab group also the button loses its listener.

    Tested with newest build: mobilesdk-1.4.1-20100909194301-osx.zip

  4. Lukasz 2011-04-15

    Is there ANY chance to solve this?

  5. Don Thorp 2011-04-15

    We're still working on the kroll rewrite, but we're getting closer to a first pass. We will use this as a test case.

  6. Don Thorp 2011-04-15

    Please verify of still an issue in 1.6. If so talk with me so we can see if it can be fixed in time.

  7. Opie Cyrus 2011-04-15

    Issue resolved via #2640. The app needs to be modified to use the {exitOnClose: false} option when creating the second tab group otherwise closing the tab would result in the root activity being closed.

    I update the test app to call tabGroup1.open() only once and also to set the exitOnClose flag. The issue can be verified by:
    1) Run attached test app.js
    2) click button and check log to verify event is fired
    3) double click on main window of tab 1 to open tab group 2
    4) hit the back button to close tab group 2 and return to tab group 1
    5) click button and check log to verify event will still fire

    Thanks
    Opie

  8. Don Thorp 2011-04-15

    If I follow the script above it works. If I do what the test says and double-click on the second tab group. It crashes with.

       D/TiAPI   ( 3296): (kroll$5) [2,71549] win3 fired dblclick listener!
       E/KrollCallback( 3296): (kroll$5) [94,71643] ECMA Error evaluating source, invocation: [callMethod UI.Window.UI.Window:event:dblclick null], message: ReferenceError: "tabGroup2" is not defined. (app://app.js#125)
       E/KrollCallback( 3296): org.mozilla.javascript.EcmaError: ReferenceError: "tabGroup2" is not defined. (app://app.js#125)
       E/KrollCallback( 3296):     at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3761)
       E/KrollCallback( 3296):     at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3739)
       E/KrollCallback( 3296):     at org.mozilla.javascript.ScriptRuntime.notFoundError(ScriptRuntime.java:3824)
       E/KrollCallback( 3296):     at org.mozilla.javascript.ScriptRuntime.name(ScriptRuntime.java:1760)
       E/KrollCallback( 3296):     at org.mozilla.javascript.Interpreter.interpretLoop(Interpreter.java:1790)
       E/KrollCallback( 3296):     at script(app://app.js:125)
       E/KrollCallback( 3296):     at org.mozilla.javascript.Interpreter.interpret(Interpreter.java:854)
       E/KrollCallback( 3296):     at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:164)
       E/KrollCallback( 3296):     at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:426)
       E/KrollCallback( 3296):     at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3161)
       E/KrollCallback( 3296):     at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:162)
       E/KrollCallback( 3296):     at org.appcelerator.titanium.kroll.KrollCallback.callSync(KrollCallback.java:139)
       E/KrollCallback( 3296):     at org.appcelerator.titanium.kroll.KrollCallback$1.run(KrollCallback.java:163)
       E/KrollCallback( 3296):     at android.os.Handler.handleCallback(Handler.java:587)
       E/KrollCallback( 3296):     at android.os.Handler.dispatchMessage(Handler.java:92)
       E/KrollCallback( 3296):     at android.os.Looper.loop(Looper.java:123)
       E/KrollCallback( 3296):     at org.appcelerator.titanium.kroll.KrollHandlerThread.run(KrollHandlerThread.java:73)
       E/TiContext( 3296): (kroll$5) [8,71651] Rhino Error: app://app.js:125,0
       E/TiContext( 3296): (kroll$5) [1,71652]  Message: ReferenceError: "tabGroup2" is not defined. (app://app.js#125)
       E/TiContext( 3296): (kroll$5) [0,71652]  Source: null
       
  9. Opie Cyrus 2011-04-15

    Fixed test to address error found by Don.

    New test attached.

  10. Bill Dawson 2011-04-15

    Emulator 2.2, ba41eca7d

    Verified the updated app.js ...

    • does not fail when double-clicking (the error Don saw).
    • still shows event firing (in logcat) even when going to second tab group and back again to first tab group and clicking the button.

JSON Source