06-02-2010 01:21 AM
Hi,
I am currently writing an ExitApplicationAction which would successfully exit my application when invoked.This action may be invoked from the menu or on click of a button.I am using FULLSCREEN as the base screen for the entire application.
I tried using the following code on my fullScreen :
public boolean onClose() {
setDirty(false);
return super.onClose();
}
However, nothing happens even though the code is executed.
Then I tried using the FullScreen.DEFAULT_CLOSE style on my Fullscreen and running the same code, then the application is exited successfully.
Now my problem is : If I use the FullScreen.DEFAULT_CLOSE, the Close menu item appears on every screen, which my application does not require.
Is there a clean way to just exit my application without requiring to have the default Close menu item?
I also tried using the System.exit(0), but read somewhere that it is not the correct way to exit an application.
I am sure this is a petty issue and many of u must have come across it.
In anticipation of an early and prompt reply,
Thanks..
Solved! Go to Solution.
06-02-2010 02:06 AM
onClose does not do anything itself, it is used for when you want to do some processing before you screen closes. Call (screenname or this).close() to actually close the screen.
06-02-2010 02:15 AM
hi!
Just an idea...
write a fuction what you call when you need, and in that function get the display stack and pop out all screens from the stack, after the last screen popped out from the stack the application will exit.
06-02-2010 02:25 AM
public boolean onClose()
{
UiApplication.getUiApplication().popScreen(this);
System.exit(0);
}
System.exit will terminate if any other process be continue in the application
06-02-2010 02:32 AM
I iterated over all the screens present on the display stack and invoked a screen.close() on it.This successfully exited my application.
Thanks for the prompt response.. ![]()
06-02-2010 02:36 AM
@dynamicDhaka :I did try using the System.exit(0) but in a book called "Beginning BlackBerry Development" by Anthony Rizk, it says :
"Exiting the Application
Generally, a BlackBerry application exits when the last screen is removed from the
display stack (by closing it). You may have noticed the System.exit() method, which will
exit the application, but it’s recommended to avoid this and properly clean up the
application on exiting by closing all screens instead. When the application exits, all
application state will be cleaned up, and the next time the user clicks the application
icon the main method will be called again with a new process."
So, I suggest using the screen.close() api for a cleaner approach.
Thanks for the response though.. ![]()
06-02-2010 07:21 AM
close() method basically popup the screen.in my derived method manullay i have done the popping task and then exit() the application. ,System.exit(0) destroy the process for the application.so..whats your problem for new process when u click the application.because previous process has been destroyed.again.using Screen.close() have few problem.like that,you have explore 4 or 5 application which use Screen.close()...in this case ..4/5 process will exist in the system which is bad for processor...i think..you have realized.....