Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-17715] Android: Cannot open new window after last window closes

GitHub Issuen/a
TypeBug
PriorityMedium
StatusClosed
ResolutionInvalid
Resolution Date2014-09-18T17:39:31.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsAndroid
Labelsandroid, regression
ReporterCaleb Cox
AssigneePing Wang
Created2014-09-17T02:17:18.000+0000
Updated2017-03-22T21:51:21.000+0000

Description

After closing the last window on Android, when attempting to open a new window, the app crashes with the "Unfortunately app has stopped" message. Here is the stack trace that I get: {noformat} E/AndroidRuntime( 2450): FATAL EXCEPTION: main E/AndroidRuntime( 2450): Process: com.appdev.test, PID: 2450 E/AndroidRuntime( 2450): java.lang.NullPointerException E/AndroidRuntime( 2450): at android.content.ComponentName.(ComponentName.java:77) E/AndroidRuntime( 2450): at android.content.Intent.(Intent.java:3813) E/AndroidRuntime( 2450): at ti.modules.titanium.ui.WindowProxy.handleOpen(WindowProxy.java:128) E/AndroidRuntime( 2450): at org.appcelerator.titanium.proxy.TiWindowProxy.handleMessage(TiWindowProxy.java:88) E/AndroidRuntime( 2450): at ti.modules.titanium.ui.WindowProxy.handleMessage(WindowProxy.java:399) E/AndroidRuntime( 2450): at android.os.Handler.dispatchMessage(Handler.java:98) E/AndroidRuntime( 2450): at android.os.Looper.loop(Looper.java:136) E/AndroidRuntime( 2450): at android.app.ActivityThread.main(ActivityThread.java:5017) E/AndroidRuntime( 2450): at java.lang.reflect.Method.invokeNative(Native Method) E/AndroidRuntime( 2450): at java.lang.reflect.Method.invoke(Method.java:515) E/AndroidRuntime( 2450): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779) E/AndroidRuntime( 2450): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) E/AndroidRuntime( 2450): at dalvik.system.NativeStart.main(Native Method) {noformat} Here is the test case that I am using:
var openWindow = function(index) {
    var window = Ti.UI.createWindow({
        backgroundColor: 'white',
        title: 'Window ' + index
    });
    var button = Ti.UI.createButton({
        width: 80,
        height: 40,
        title: 'Button'
    });
    button.addEventListener('click', function() {
        window.close();
        openWindow(index + 1);
    });
    window.add(button);
    window.open();
};
openWindow(1);
It successfully closes the first window but crashes when attempting to open the second window. It works when opening the second window before closing the first.

Comments

  1. Ingo Muschenetz 2014-09-17

    May I ask what classifies this as a regression? Did it previously work in an earlier version of the SDK?
  2. Caleb Cox 2014-09-17

    Yes, the exact same code runs without crashing using Titanium SDK 3.2.3. Sorry for not explicitly mentioning that earlier.
  3. Ingo Muschenetz 2014-09-17

    [~pwang] can you please take a look?
  4. Ping Wang 2014-09-17

    Starting from 3.3.0, we set exitOnClose to true by default for the first window (see [PR#5602](https://github.com/appcelerator/titanium_mobile/pull/5602)), which means once the first window is closed the whole application is closed. That's why the app crashes when you open the second window. To make the above test case run, we can modify it
       var openWindow = function(index) {
           var window = Ti.UI.createWindow({
               backgroundColor: 'white',
               title: 'Window ' + index,
               exitOnClose: false  //Override the default behavior
           });
           var button = Ti.UI.createButton({
               width: 80,
               height: 40,
               title: 'Button'
           });
           button.addEventListener('click', function() {
               window.close();
               openWindow(index + 1);
           });
           window.add(button);
           window.open();
       };
       openWindow(1);
       
  5. Caleb Cox 2014-09-17

    I verified that the change you suggested fixes my issue. Thanks for your help! Someone should update the documentation to reflect the new default value of exitOnClose.
  6. Ping Wang 2014-09-18

    This change has been in the 3.3.0 Release Notes. Will update the default value of exitOnClose. PR: https://github.com/appcelerator/titanium_mobile/pull/6127 3_4_X PR: https://github.com/appcelerator/titanium_mobile/pull/6128 Resolved the ticket as invalid.
  7. Mark Mokryn 2014-10-02

  8. Lee Morris 2017-03-22

    Closing ticket as invalid with reference to previous comments.

JSON Source