12-20-2011 04:56 PM
i have a problem with a Java application freezing when the app is closed. it occurs on torch 9800 with os6 (but not the corresponding simulator), but the same application is working fine on a 9700 with os6. by freeze i mean that the app's last screen remains visible and the device is unresponsive. however, it's possible to recover use of the device by switching apps, at which point the app in question is no longer in the application list.
the application is exiting using System.exit(0), after which i'm not seeing any error or stack trace in the log. the app registers several GlobalEventListeners, as well as RadioStatusListener, CoverageStatusListener, WLANConnectionListener, and possibly a few others. I've tried to unregister the listeners before exiting but it doesn't seem to prevent freezing. the app has a pool of threads for making HTTP connections, but i'm under the impression that these don't need to be cleaned up explicitly.
the symptoms are similar to this issue: https://www.blackberry.com/jira/browse/JAVAAPI-175
i'm fairly new to BB development, so any suggestions for debugging this issue are appreciated.
12-20-2011 05:08 PM
Welcome to the forum.
The usual cause of a 'locked screen' on exit is that you have popped the last screen off the stack, but not closed the app. My guess therefore is that there is something that blocks for while in your shutdown code. I would put logging points in you shutdown code and time how long it takes.
One way to stop this being obvious would be to requestBackground at the start of your shutdown code.
I must admit that I always terminate the network Threads. This can be a problem, as Thread.interrupt does not seem to 'break' a connection. So I generally also code a stop routine in the Thread that closes the httpConnection object if it is non null. This will typically cause the processing to throw an exception. So you have to handle that gracefully when in 'stop state'. But I am not sure this is your problem.
Let us know how you get on.
12-20-2011 09:59 PM
Thanks Peter... actually after sending the app to the background and then calling System.exit in the application's deactivate method, the app only hangs for a few seconds. Does that shed any light on the cause of the problem?
12-21-2011 04:31 AM
Not to me I'm sorry.
But even a few seconds seems quite a long time. Have you logged the various steps in the shutdwon to see if the delay associated with one of your actions? Or perhaps the network Threads, though I am really not sure how you would log this.
Of course this could always be an OS bugette.
Just one thing and I am sure you have this covered but for other readers be aware that deactivate is called whenever the app is sent to the Background, for example when using switch application. So you can't just add a System.exit() in there.
12-23-2011 03:28 AM - edited 12-23-2011 03:30 AM
Are you closing or popping the screen before calling System.exit ?
Also it is indeed important to remove all listeners, otherwise an instance of your app's class might be kept in memory and you might even get a "previous instance still active" issue which can cause closing lags.
if you have DEFAULT_CLOSE set in the MainScreen, then closing the main screen should close the app without calling System.exit. Just in case, what I usually do is override close() in the main screen and have that call a shutdown function in the app's class that removes all listeners, kills all timers and services, etc., then call super.close() and then do System.exit in an invokeLater as a sure-kill of the app after the screen is fully closed.