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
New Developer
Posts: 44
Registered: ‎08-20-2008
My Device: Not Specified

App won't exit

Any advice for how a debug an app that won't completely exit?  Static data is preserved between launches of the app, and it starts up showing our shutdown screen.. So something seems to be keeping it running in the background, even though it appears to have exited.  We use a couple of threads, but it *seems* like we shut all those down properly/

 

If anyone has advice for diagnosing / fixing this, would be greatly appreciated!

 

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

Re: App won't exit

If do you a System.exit(0), I believe all your threads are shutdown anyway.

 

I wonder if the garbage collector is not releasing the storage associated with your static data immediately, then the system saves itself the bother of recreating the Object and just reuses the one there?  Don't know if that is legal java.  However I would suggest that you avoid using Static storage if you can, too many people use it and assume it guarantees a Singleton, which it does not (at least not in the BlackBerry JVM).  I would recommend RuntimeStore.

 

Sorry can't help more.  I'm sure one of the many people on this forum who are more skilled in java will give you a better answer.

Developer
Posts: 131
Registered: ‎08-13-2008
My Device: Not Specified

Re: App won't exit

[ Edited ]
Edit: see my next post
Message Edited by KeniF on 08-29-2008 10:49 AM
BlackBerry Development Advisor
Posts: 15,694
Registered: ‎07-09-2008
My Device: BlackBerry PRIV
My Carrier: Bell

Re: App won't exit

What is happening in the 2 entry points?  Are they both entering the event dispatcher, is one registering a listener, etc..?  Where is the System.exit call being made from (menu item, listener method, etc...)?
Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Developer
Posts: 131
Registered: ‎08-13-2008
My Device: Not Specified

Re: App won't exit

[ Edited ]

Ok, I've just checked my backup folder and I realised I've made a mistake (ignore my previous post)

 

What I did was have the main class MyApp extend UiApplication, put a constructor in it which creates a new MyGUI, which extends MainScreen.

 

//MyApp extends UiApplication

public static void main(String[]args){
// Load the GUI (entry point 1)
if(args!=null&&args.length>0&&args[0].equals("gui")){
MyApp myApp=new MyApp();

}// GUI

else{ // Blackberry Autostart (entry point 2)
//makes sure only 1 instance is created
bgThread=BackgroundThread.waitForSingleton();
bgThread.start();

}// autostart
}//main

private MyApp(){
myGUI=new MyGUI();
BackgroundThread.waitForSingleton().setGUI(myGUI);
pushScreen(myGUI);
this.enterEventDispatcher();
}

//MyGUI class, extends MainScreen
public void close(){
System.exit(0); //won't kill background thread
}

 

 

Message Edited by KeniF on 08-29-2008 10:51 AM
Message Edited by KeniF on 08-29-2008 10:53 AM
Highlighted
Developer
Posts: 52
Registered: ‎07-17-2008
My Device: Not Specified

Re: App won't exit

To KeniF's point, what I have also noticed is that "gui" and "autostart" entry points will have their own static contexts.  Wha

What I mean is if a static variable is initialized in "autostart" entry point, the value will not be available when  the app is invoked via "gui" entry point.

 

This is unique to BlackBerry JVM, probably for a reason.   Each entry point is treated as a separate application, so to speak.  In the exampe KeniF has posted, only calling System.exit(n) within the "autorun" context will  exit the bgThread.  Other option is to   set a flag or something (in the colse() method) on the bgThread object to indicate that it should exit.

Developer
Posts: 131
Registered: ‎08-13-2008
My Device: Not Specified

Re: App won't exit

[ Edited ]

Yeah, but I have a workaround to this:

 

//MyApp extends NOTHING
//main method

if(args!=null&&args.length>0&&args[0].equals("gui")){
myGUI=new MyGUI();
myGUI.enterEventDispatcher();
}// GUI

//MyGUI class extends UiApplication
MyGUI{
MainScreen ms=new MainScreen(){
public void close(){
System.exit(0); // Will kill entire application
}//close
}; //mainscreen
pushScreen(ms);
}//MyGUI

Message Edited by KeniF on 08-29-2008 11:30 AM
Developer
Posts: 52
Registered: ‎07-17-2008
My Device: Not Specified

Re: App won't exit

Like this workaround much better!
New Developer
Posts: 44
Registered: ‎08-20-2008
My Device: Not Specified

Re: App won't exit

Follow-up to this thread:  Is System.exit(0) supposed to throw a SecurityException?  If so, why does that get thrown?
Developer
Posts: 1,415
Registered: ‎07-30-2008
My Device: Not Specified

Re: App won't exit

Static data is a "property" of a class, not an "app." For example,

 

http://java.sun.com/docs/books/jls/unloading-rationale.html

 

 

You don't normally expect classes to go away once they are loaded. If you have a different instance of the

jvm, or different namespace or universe, then ok past loads of a given class are not visible.

Otherwise, you expect to find an "old" class once you reference it after it has been already loaded.