Search code examples
blackberryjde

Problems killing a custom blackberry app


All of my screens inherent from a screen with the following onClose() method:

    public boolean onClose()
    {
        Dialog.alert("Closing");
        done = true;
        System.exit(0);

        return true;
    }

I kind of assumed that System.exit(0); would actually kill my application.

If I hit the red button to completely exit, I do get a "Closing" dialog message sucessfully. Same if I hit the back button too many times. But even if I get that "Closing" dialog, I'll still see my application running in the background when I select "Switch Application".

Not only that, if I have a thread running, sometimes I'll still see it going after I've quit the application (which is why I have that done variable set, so that my threads will automatically abort if done is true).

And on top of that, if the application crashes, I definitely don't see my dialog message, even if i manage to leave the application entirely. If I try to reclick the application after it's crashed, it doesn't reload, too. Ever. Is there anyway to gracefully handle that situation? (Obviously I have supplied error handling for every problem I've found, but if something happens in the wild, I want at least the application to not continue eating up memory)

Do Blackberry apps just never close? Am I doing something wrong? Right now if I want my application to stop running, I have to completely delete it and reinstall it!


Solution

  • If you are extending net.rim.device.api.ui.Screen (not MainScreen or some other child of Screen) then you should ether specifically set DEFAULT_CLOSE style or implement something similar calling close() when the screen should be taken down per the API docs:

    public boolean onClose()
    
    Indicates a close event has occurred.
    
    The default implementation is activated by specifying DEFAULT_CLOSE. It will call onSavePrompt() if the screen is dirty, then call close() if successful.
    
    Returns:
        True if the screen closes; otherwise, false.
    Since:
        JDE 3.6.0
    

    Calling System.exit(0) should result in your app exiting however there may be hold offs in the implementation to allow threads to exit and screens to close cleanly. The normal way for a blackberry GUI application to exit is when the last screen is popped off the display stack, which happens when close() is called.