Search code examples
codenameone

Codename One stop() method: why don't we keep Dialog?


The default Codename One method is:

public void stop() {
        current = getCurrentForm();
        if (current instanceof Dialog) {
            ((Dialog) current).dispose();
            current = getCurrentForm();
        }
    }

Is it really necessary to dispose a Dialog? Why? Advantages and disadvantages of eliminating the Dialog related code?


Solution

  • start() is invoked to restore the app. So if it's minimized stop() will be invoked and dispose the dialog. Let's say it doesn't do that... start() will be invoked again and dialog will be shown again.

    The show() method of dialog is blocking. So it will stop the current callback in its tracks and effectively botch the whole restore process.

    As an alternative we tried in the past to check if this is a dialog on restore and use showModless() but this has issues with some port code that also invokes show() on the current Form. The only solution that might work is to save the dialog instance as a special case and dispose it. Then re-show it with a callSerially() in start().