"Reopen" tabGroup causes "activity reference is invalid, removing from activity stack" NullPointerException

You must Login before you can answer or comment on any questions.

We have an android application with a main window that has just a view opening a tabGroup with 2 tabs. On android:back event we clear all events and children of the windows and return to the main window by closing the tabGroup.

Doing these actions repeatedly (open tabGroup, press android back button) crashes the application in the emulator on a random open tabGroup.

Code is

app.js

var mainwin = Ti.UI.createWindow({
    title:'Emporiki Rent',
    backgroundColor:'#fff',
    fullscreen:true,  
    statusBarHidden: true,
    navBarHidden:true, 
    exitOnClose:true
});
 
var icon1Image = Ti.UI.createView({
    backgroundColor:'#000',
    height:50,
    width:50,
    top:50,
    left:50
});
 
var MY_TABGROUP = require('/myTabGroup').innerTabGroup;
 
icon1Image.addEventListener('click', function(e) {
 
    Ti.API.debug('...............................................');
    MY_TABGROUP().open({
        animated: true
    });
    Ti.API.debug('...............................................');
});
 
mainwin.add(icon1Image);
 
mainwin.open();

myTabGroup.js

exports.innerTabGroup = function() {
 
    var tabGroup = Titanium.UI.createTabGroup();
 
    var win1 = Titanium.UI.createWindow({  
        title:'Tab 1',
        backgroundColor:'#fff'
    });
 
    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);
 
    win1.addEventListener('android:back', test);    
 
    var tab1 = Titanium.UI.createTab({  
        icon:'KS_nav_views.png',
        title:'Tab 1',
        window:win1
    });
 
    var win2 = Titanium.UI.createWindow({  
        title:'Tab 2',
        backgroundColor:'#fff'
    });
 
    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);
 
    function test() {
        win1.removeEventListener('android:back',test);
        win2.removeEventListener('android:back',test);
 
        win1.remove(label1);
        label1 = null;
 
        win1 = null;
 
        win2.remove(label2);
        label2 = null;
 
        win2 = null;
 
        tabGroup.remove(tab1);
        tab1 = null;
        tabGroup.remove(tab2);
        tab2 = null;
        tabGroup.close();
        tabGroup = null;    
        Ti.API.info("OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO");
    }
 
    win2.addEventListener('android:back', test);
 
    var tab2 = Titanium.UI.createTab({  
        icon:'KS_nav_ui.png',
        title:'Tab 2',
        window:win2
    });
 
    tabGroup.addTab(tab1);  
    tabGroup.addTab(tab2);  
 
    return tabGroup;
 
};

Stacktrace is

I/ActivityManager( 60): Starting activity: Intent { cmp=com.greekgeeks.empty/ti.modules.titanium.ui.TiTabActivity (has extras) } W/ActivityManager( 60): startActivity called from non-Activity context; forcing Intent.FLAG_ACTIVITY_NEW_TASK for: Intent { cmp=com.greekgeeks.empty/ti.modules.titanium.ui.TiTabActivity (has extras) } D/TiAPI ( 473): ............................................... W/TiTabActivity( 473): (main) [3467,36049] Notifying TiTabGroup, activity is created I/ActivityManager( 60): Displayed activity com.greekgeeks.empty/ti.modules.titanium.ui.TiTabActivity: 388 ms (total 388 ms) I/TiAPI ( 473): OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO W/InputManagerService( 60): Starting input on non-focused client com.android.internal.view.IInputMethodClient$Stub$Proxy@43fee480 (uid=10040 pid=473) E/TiBaseActivity( 473): (main) [1374,37423] Layout cleanup. D/TiAPI ( 473): ............................................... D/dalvikvm( 473): GC_FOR_MALLOC freed 4389 objects / 340224 bytes in 61ms I/TiApplication( 473): (KrollRuntimeThread) [941,38364] activity reference is invalid, removing from activity stack D/AndroidRuntime( 473): Shutting down VM W/dalvikvm( 473): threadid=1: thread exiting with uncaught exception (group=0x4001d800) E/TiApplication( 473): (main) [7,38371] Sending event: exception on thread: main msg:java.lang.NullPointerException; Titanium 1.9.0,2012/01/24 23:31,3e68438 E/TiApplication( 473): java.lang.NullPointerException E/TiApplication( 473): at android.content.ComponentName.<init>(ComponentName.java:75) E/TiApplication( 473): at android.content.Intent.<init>(Intent.java:2678) E/TiApplication( 473): at ti.modules.titanium.ui.TabGroupProxy.handleOpen(TabGroupProxy.java:303) E/TiApplication( 473): at org.appcelerator.titanium.proxy.TiWindowProxy.handleMessage(TiWindowProxy.java:98) E/TiApplication( 473): at ti.modules.titanium.ui.TabGroupProxy.handleMessage(TabGroupProxy.java:104) E/TiApplication( 473): at android.os.Handler.dispatchMessage(Handler.java:95) E/TiApplication( 473): at android.os.Looper.loop(Looper.java:123) E/TiApplication( 473): at android.app.ActivityThread.main(ActivityThread.java:4627) E/TiApplication( 473): at java.lang.reflect.Method.invokeNative(Native Method) E/TiApplication( 473): at java.lang.reflect.Method.invoke(Method.java:521) E/TiApplication( 473): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) E/TiApplication( 473): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) E/TiApplication( 473): at dalvik.system.NativeStart.main(Native Method) E/AndroidRuntime( 473): FATAL EXCEPTION: main E/AndroidRuntime( 473): java.lang.NullPointerException E/AndroidRuntime( 473): at android.content.ComponentName.<init>(ComponentName.java:75) E/AndroidRuntime( 473): at android.content.Intent.<init>(Intent.java:2678) E/AndroidRuntime( 473): at ti.modules.titanium.ui.TabGroupProxy.handleOpen(TabGroupProxy.java:303) E/AndroidRuntime( 473): at org.appcelerator.titanium.proxy.TiWindowProxy.handleMessage(TiWindowProxy.java:98) E/AndroidRuntime( 473): at ti.modules.titanium.ui.TabGroupProxy.handleMessage(TabGroupProxy.java:104) E/AndroidRuntime( 473): at android.os.Handler.dispatchMessage(Handler.java:95) E/AndroidRuntime( 473): at android.os.Looper.loop(Looper.java:123) E/AndroidRuntime( 473): at android.app.ActivityThread.main(ActivityThread.java:4627) E/AndroidRuntime( 473): at java.lang.reflect.Method.invokeNative(Native Method) E/AndroidRuntime( 473): at java.lang.reflect.Method.invoke(Method.java:521) E/AndroidRuntime( 473): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) E/AndroidRuntime( 473): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) E/AndroidRuntime( 473): at dalvik.system.NativeStart.main(Native Method) W/ActivityManager( 60): Force finishing activity com.greekgeeks.empty/org.appcelerator.titanium.TiActivity W/ActivityManager( 60): Activity pause timeout for HistoryRecord{43f68b38 com.greekgeeks.empty/org.appcelerator.titanium.TiActivity} W/ActivityManager( 60): Launch timeout has expired, giving up wake lock! W/ActivityManager( 60): Activity idle timeout for HistoryRecord{43f2db20 com.greekgeeks.empty/.EmptyActivity} W/ActivityManager( 60): Activity destroy timeout for HistoryRecord{43f68b38 com.greekgeeks.empty/org.appcelerator.titanium.TiActivity} I/Process ( 473): Sending signal. PID: 473 SIG: 9 I/ActivityManager( 60): Process com.greekgeeks.empty (pid 473) has died. I/WindowManager( 60): WIN DEATH: Window{44012df0 com.greekgeeks.empty/com.greekgeeks.empty.EmptyActivity paused=false} I/WindowManager( 60): WIN DEATH: Window{440154b8 com.greekgeeks.empty/org.appcelerator.titanium.TiActivity paused=false} I/UsageStats( 60): Unexpected resume of com.android.launcher while already resumed in com.greekgeeks.empty W/InputManagerService( 60): Got RemoteException sending setActive(false) notification to pid 473 uid 10040 D/SntpClient( 60): request time failed: java.net.SocketException: Address family not supported by protocol D/SntpClient( 60): request time failed: java.net.SocketException: Address family not supported by protocol D/dalvikvm( 60): GC_FOR_MALLOC freed 15090 objects / 718704 bytes in 104ms

1 Answer

Hello,

1.8.1 has a bunch of bugfixes for this issues. Can you please install 1.8.1, clean your project, and recompile with the 1.8.1?

BEst,

Mauro

— answered 3 years ago by Mauro Parra
answer permalink
2 Comments
  • Mauro, first of all thanks for your answer...

    Unfortunately, testing my project with version 1.8.1 (after cleaning the project and even deleting the android build directory and then recompiling the project with 1.8.1) din't resolve the problem.

    I found this issue (TIMOB-7240), mentioning that "It didn't remove the tab activity properly when back key is hit.". This issue is still In Progress.

    Maybe this issue relates to my problem...

    — commented 3 years ago by Athanasios Nikolaou

  • I also found these two related to my problem issues:

    TIMOB-7573

    TIMOB-7572

    — commented 3 years ago by Athanasios Nikolaou

Your Answer

Think you can help? Login to answer this question!