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
Developer
Posts: 1,123
Registered: ‎02-10-2009
My Device: 8130 / 8350 / 9530 / 9550 / 9850 / PlayBook
My Carrier: Verizon

Exiting a non-UiApplication

How do you exit an application that is derived from Application and not UiApplication as there is no close method?
Developer
Posts: 905
Registered: ‎02-07-2009
My Device: BlackBerry Torch 9800
My Carrier: Globe Telecom

Re: Exiting a non-UiApplication

From what class does the close method you are referring to come from? Screen? what i usually do is i just invoke System.exit(0);
Developer
Developer
Posts: 1,123
Registered: ‎02-10-2009
My Device: 8130 / 8350 / 9530 / 9550 / 9850 / PlayBook
My Carrier: Verizon

Re: Exiting a non-UiApplication

Yes, the close method is in the Screen class, but when you close the last Screen a UiApplication will exit. How do you get the samething in a non-UiApplication. What I have is an app that will start when you click the icon, and I want it to stop when you click it again. It seems you can't reenter an app that does not have an alternate entry point at all. But if I made an alternate entry point, how do I close the Application and can you do an alternate entry on a non-UiApplication?
Developer
Posts: 905
Registered: ‎02-07-2009
My Device: BlackBerry Torch 9800
My Carrier: Globe Telecom

Re: Exiting a non-UiApplication

I see. what you can do i think is override the close() of your screen then just invoke the requestBackground() so that your application will not close totally. 
Developer
Developer
Posts: 1,123
Registered: ‎02-10-2009
My Device: 8130 / 8350 / 9530 / 9550 / 9850 / PlayBook
My Carrier: Verizon

Re: Exiting a non-UiApplication

You can't push a screen from an application that doesn't extend UiApplication. That is why I don't get how you would close an non-UiApplication that doesn't implement some type of listener.
Developer
Posts: 905
Registered: ‎02-07-2009
My Device: BlackBerry Torch 9800
My Carrier: Globe Telecom

Re: Exiting a non-UiApplication

Yup i'm aware of that. i thought your setup is you have an alternate entry point. then you have a UIApplication which automatically runs at startup. i didn't get your issue correctly. Anyway, so just to make things clearer, you want a non UiApplication to close just like a UiApplication close? am i right?

 

you can implement a globaleventlistener in your non-UIApplication. 

then can persist a flag which will help your application determine if your application is running or not.  

then everytime you click the icon, you retrieve that flag to determine if it is running or not.

then post a global event to start/stop your non-ui application. 

Developer
Developer
Posts: 1,123
Registered: ‎02-10-2009
My Device: 8130 / 8350 / 9530 / 9550 / 9850 / PlayBook
My Carrier: Verizon

Re: Exiting a non-UiApplication

I don't think a global event listener will make a differnence as every time I click on the icon it says the app is already started. Even with an alternate entry point, I can't click the icon more than once.
Developer
Posts: 905
Registered: ‎02-07-2009
My Device: BlackBerry Torch 9800
My Carrier: Globe Telecom

Re: Exiting a non-UiApplication

can you post a snippet of your code main() of your non-UiApplication? i think there should be logic on when to invoke the appEventDispatcher.
Developer
Developer
Posts: 1,123
Registered: ‎02-10-2009
My Device: 8130 / 8350 / 9530 / 9550 / 9850 / PlayBook
My Carrier: Verizon

Re: Exiting a non-UiApplication

public static void main(String [] args){ try { ApplicationManager app = ApplicationManager.getApplicationManager(); boolean keepGoing = true; while (keepGoing) { if (app.inStartup()) { try{ Thread.sleep(15000); } catch (Exception e){ System.out.println(e.toString()); } } else { keepGoing = false; } } runStore = RuntimeStore.getRuntimeStore(); if( args.length > 0 ){ instance = new QuietTime(); runStore.put(KEY, instance); } else { instance = (QuietTime) runStore.get(KEY); if( instance == null ){ System.out.println("INSTANCE WAS NULL"); instance = new QuietTime(); } if( enabled ){ System.out.println("SHUTTING DOWN APP"); instance.disable(); } else { instance.enable(); } //System.exit(0); } }catch(Exception e){ System.out.println(e.toString()); } }

 

If I leave the System.exit(0) commented out then it will run as expected, but I cannot close the app. If I uncomment the System.exit(0), then the app closes immediately after starting. I tried changing it to an alternate entry point app and it still does the same whether it has one entry or two. It will only allow the app to start once and if I use System.exit(0) it closes the app and not just that entry point.
Developer
Posts: 905
Registered: ‎02-07-2009
My Device: BlackBerry Torch 9800
My Carrier: Globe Telecom

Re: Exiting a non-UiApplication

from your code:

 

while (keepGoing) { if (app.inStartup()) { try{ Thread.sleep(15000); } catch (Exception e){ System.out.println(e.toString()); } } else { keepGoing = false; } 

}

 

 

where do you need this for?

 

how did you setup your alternate entry point?

 

http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800901/How_To_-_Setup...