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
Posts: 70
Registered: ‎08-18-2008
My Device: Not Specified

How to know when UiApplication is terminated?

Hi,

 

I have a native BB app, my main class extends UiApplication. Is there a method we can override to know when the user has terminated the application? I need to do some cleanup when the app is done. I see deactive(), but I think that's just for when the app is pushed into the background, not terminated,

 

Thanks

 

 

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

Re: How to know when UiApplication is terminated?

I am not aware of anything like this, though it makes some sense that something like this is possible.

 

How I do this is never code System.exit(n) in any application code, but instead have it in some shared code, say a myExit(int rc) method, which is also responsible for tidying everything up.  If anything wants to 'exit', it has to call myExit.  Works OK for me.

Developer
Posts: 94
Registered: ‎10-01-2009
My Device: Not Specified

Re: How to know when UiApplication is terminated?

I've seen code samples with an onExit method, but I don't see it in the API.  Deprecated/removed?  Wrong API?  Anybody know?

 

You might contrive to run the app in its own thread and do a join to know when the thread terminates, but that sound like overkill.

 

Since you're using UIApplication, you're probably using a Screen, so it might be enough for you to override the onClose method for the first Screen you push.

 

Highlighted
Developer
Posts: 70
Registered: ‎08-18-2008
My Device: Not Specified

Re: How to know when UiApplication is terminated?

Thanks guys, that makes sense, I'll go with that option,


Mark

Developer
Posts: 1,474
Registered: ‎04-14-2009
My Device: Not Specified

Re: How to know when UiApplication is terminated?

To add to all of the above, you can build a polling mechanism based on Application.isAlive() to check whether the process in which the application is running is still alive.