Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
hiral
Posts: 54
Registered: ‎11-12-2009
My Device: Not Specified
Accepted Solution

Successfully exit an application

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..

Please use plain text.
Developer
Developer
CMY
Posts: 1,120
Registered: ‎02-10-2009
My Device: 8130 / 8350 / 9530 / 9550 / 9850 / PlayBook
My Carrier: Verizon

Re: Successfully exit an application

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.

Please use plain text.
Developer
sannyo
Posts: 148
Registered: ‎11-16-2009
My Device: Not Specified

Re: Successfully exit an application

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.

Please use plain text.
Developer
dynamicdhaka
Posts: 101
Registered: ‎12-10-2009
My Device: styile 9670
My Carrier: SingTel

Re: Successfully exit an application

you can use it ..

 

public boolean onClose()

{

UiApplication.getUiApplication().popScreen(this);

System.exit(0);

}

 

System.exit will terminate if any other process be continue in the application

 

Mobile Application Advisor
Please use plain text.
Developer
hiral
Posts: 54
Registered: ‎11-12-2009
My Device: Not Specified

Re: Successfully exit an application

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.. :smileyhappy:

Please use plain text.
Developer
hiral
Posts: 54
Registered: ‎11-12-2009
My Device: Not Specified

Re: Successfully exit an application

@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.. :smileyhappy:

Please use plain text.
Developer
dynamicdhaka
Posts: 101
Registered: ‎12-10-2009
My Device: styile 9670
My Carrier: SingTel

Re: Successfully exit an application

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.....

Mobile Application Advisor
Please use plain text.