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
Trusted Contributor
Posts: 174
Registered: ‎09-04-2011
My Device: Bold
My Carrier: at&t
Accepted Solution

Background Application Exit event

Hi, expert,

 

from this post: http://supportforums.blackberry.com/t5/Java-Development/Trap-application-exit-close-event-on-Exit-Ba..., it looks like that we would need to look at the Screen.close method to implement any exit code for our UI application (actually the UiApplication.getScreenCount would tell us how many screen on display stack. If that number is 1, it means that this is the last screen to close instead of trying to figure out which is the home screen).

 

however for background application, it is a little tricky. There are SystemListener.powerOff and SystemListener2.powerOffRequested could be used to signal a device reboot which could be used to trigger a shutdown of my background application. However what if user cancelled the power off and then my background application would not be running any more.

 

So just wonder if there is any good practice for shutdown and cleaning up the background process. Or maybe that it doesn't matter since anyway device is rebooting or power off.

 

Could someone share some insights on this?

Developer
Posts: 729
Registered: ‎05-04-2011
My Device: 9700

Re: Background Application Exit event

Besides saving all the data you need, one thing I can think of is to update your system listeners (the listeners which stays active after application / device are shut down. For example, SystemListener). If you want one (or more) of the listeners to be enabled or not, you should do it on shutdown so your application (won't) start working when it (shouldn't) should.  

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Background Application Exit event

I generally use SystemListener.powerOff() but was under the impression that this only  got called after the user had agreed the powerOff.  Remember that this is normally only a sleep mode so powerOn will be invoked (assuming you leave your System Listener enabled) and you can restart everything.  I don't believe there is an indication of a full device power off. 

 

Anyway, I would use powerOff and PowerOn for both UiApplications and Applications.

 

It is good practice to do this - it will save things like network Threads dieing and not being restarted overnight when the user automatically shuts their BB down. 

 

In the case of UiApplication, often you might want to give the user the option of exiting the application via a menu commend.  So you could create a shared exit method that everyone (including the no more screen close), can use. 

Trusted Contributor
Posts: 174
Registered: ‎09-04-2011
My Device: Bold
My Carrier: at&t

Re: Background Application Exit event

Thanks very much for the insight.