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: 103
Registered: ‎11-07-2010
My Device: Not Specified
Accepted Solution

restart application automatically

Dear all,

 

i have a BB application which have two application modules, (two classes extends UIApplication).

 

which acts as server and client ,

how i can restart on of those two applications without affecting the other module?

 

is this possible ?

 

Thanks,

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

Re: restart application automatically

Absolutely.  Look at the various ApplicatinMenenger methods.  For example, here is code to restart the currrent Applciation:

 

ApplicationDescriptor current = ApplicationDescriptor.currentApplicationDescriptor();
ApplicationManager.getApplicationManager().scheduleApplication(current, System.currentTimeMillis() + 2001, true);
System.exit(0);

 

Remember that once your main does a enterEventDispatcher(), this will not return. 

Highlighted
Trusted Contributor
Posts: 103
Registered: ‎11-07-2010
My Device: Not Specified

Re: restart application automatically

i tried this code before,

this code restarts the whole application, i need only to restart the current entry point not the whole application

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

Re: restart application automatically

How do you start each of your UiApplication?  Assuming the start are started separately, they have different ApplicationDescriptors.  So you should be able to specify the ApplicationDescriptor for the one that you want to start?

Trusted Contributor
Posts: 103
Registered: ‎11-07-2010
My Device: Not Specified

Re: restart application automatically

i have the two entry points one always running and one that could ne claused.

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

Re: restart application automatically

" .. and one that could ne claused."

 

I'm not sure what this means.

 

Also I'm not sure what you mean by Entry points.  There is only one Entry point to an Application or UiApplication - its main(..).  Once you have come into that, you start an Application.  The combination of Application and parameters used to to start the Application make up the ApplicationDescriptor. 

 

Finally, you said:

"this code restarts the whole application"

Possibly this is because you are running this code in the wrong Application. 

Trusted Contributor
Posts: 103
Registered: ‎11-07-2010
My Device: Not Specified

Re: restart application automatically

i meant that i have two clases which implemets UIApplication one have Main method and the other doesnot have main.

 

the one which doesn't have main is always in background and dont have an icon , its a hidden application.

 

all i need to make is to restart this one which is always on the background and not seen periodically withour restarting the other application.

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

Re: restart application automatically

OK, then can we go back to a question I asked a while back:

How do you start each of your UiApplications? 

Trusted Contributor
Posts: 103
Registered: ‎11-07-2010
My Device: Not Specified

Re: restart application automatically

[ Edited ]

if (args != null && args.length > 0
                    && args[0].equalsIgnoreCase("AutoStartUp")) {
                PTClockListener ptClockListener = new PTClockListener();
                ptClockListener.enterEventDispatcher();
            } else {
                MainAPP instance = new MainAPP();
                instance.enterEventDispatcher();
            }

 

thia is the code which run, the server application have this arg "AutoStartUp"

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

Re: restart application automatically

Ok, here is how I would do it, assuming that I know that

PTClockListener

is still working.

 

1) I would add a GlobalEventListener to PTClockListener

2) In the processing for the GlobalEvent, I would issue the restart code as given previously.

3) I would send the GlobalEvent whenever I wanted the  PTClockListener to restart.

 

You will find this useful for GlobalEvents:

http://supportforums.blackberry.com/t5/Java-Development/Global-Events-and-Global-Event-Listeners/ta-...

 

There are other ways, bt I think this is the cleanest.