tags:

views:

537

answers:

2

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!

+1  A: 

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.

Richard
Yeah, I'm using MainScreen, sorry not to clarify. Hrmm...I thought that's what System.exit(0) did...it's confusing for me that it's not working. Maybe some of my threads aren't exiting properly, thus the program continues to run.... i'll look into it, thanks for the advice
Jenny
If you still think your threads aren't closing, you could try making sure that "done" is volatile and to call join on the extra threads.
Andres
A: 

Don't call System.exit(0) call super.onClose() unless as he says below your not overridding MainScreen

haagmm
Hrrm...that helps for the case where I hit back until the application has popped all the screens... Is there any way to handle a user hitting the red exit button?
Jenny
The default behavior for the red (hang up) button is to background the application. If you want it to exit (without saving) then you could keep track of your screens and call close() on all of them, or set a flag call close() on the current screen, then in onExposed() call super.onExposed() then check the flag and conditionally call close().
Richard