BlackBerry Forums Support Community
              

Closed Thread
 
Thread Tools
Old 06-30-2006, 02:04 PM   #1
phil_doyle
Knows Where the Search Button Is
 
Join Date: Sep 2005
Model: 7520
Posts: 31
Default [Resolved] How to terminate program and have it restart

Please Login to Remove!

is there a way for me to code my program so that it is able to terminate the program on its own and then restart itself after a given amount of time (5 minutes)?

Last edited by phil_doyle; 07-13-2006 at 07:44 PM.. Reason: update status to resolved
Offline  
Old 07-07-2006, 06:00 AM   #2
andychambers
New Member
 
Join Date: Apr 2006
Model: 7100T
Posts: 10
Default

To close your application after some amount of time, use the sleep() method in your close routine.

To cause it to restart at a specified time, you can use ApplicationManager.scheduleApplication().
Offline  
Old 07-13-2006, 04:27 PM   #3
phil_doyle
Knows Where the Search Button Is
 
Join Date: Sep 2005
Model: 7520
Posts: 31
Default

thanks for the help

here is the code i'm using
Quote:
try
{
ApplicationManager appManager = ApplicationManager.getApplicationManager();

ApplicationDescriptor template = ApplicationDescriptor.currentApplicationDescriptor ();
String[] args = { "restart" };
ApplicationDescriptor descriptor = new ApplicationDescriptor(template, args);

// have application restart after 10 sec
Date _date = new Date();
long restartTime = _date.getTime() + (1000 * 10);
_date = null;

appManager.scheduleApplication(descriptor, restartTime, true);
}catch (Exception e) { }
System.exit(0);
however, now i have the problem where i can have two instances of the program running. if my application restarts through the scheduleApplication, i am able to launch another instance of the application.
Offline  
Old 07-13-2006, 04:54 PM   #4
phil_doyle
Knows Where the Search Button Is
 
Join Date: Sep 2005
Model: 7520
Posts: 31
Default

i guess i solved that problem by adding a code in the main that will check if the application is running already

Quote:
public static void main(String[] args)
{
ApplicationDescriptor descriptor = ApplicationDescriptor.currentApplicationDescriptor ();
String currentApplicationName = descriptor.getName();

ApplicationManager manager = ApplicationManager.getApplicationManager();
ApplicationDescriptor descriptors[] = manager.getVisibleApplications();

for (int i = 0; i < descriptors.length; i++)
{
if (currentApplicationName.equals(descriptors[i].getName()))
{
manager.requestForeground(manager.getProcessId(des criptors[i]));
return;
}
}
....
}
Offline  
Closed Thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


HP 3488A HPIB Switch / Control Unit Mainframe picture

HP 3488A HPIB Switch / Control Unit Mainframe

$24.99



Tektronix TM503 3-Bay Test Equipment Mainframe Power Supply  picture

Tektronix TM503 3-Bay Test Equipment Mainframe Power Supply

$59.99



Tektronix TM515 5-Bay Traveler Mainframe for TM5000 Series System D1 picture

Tektronix TM515 5-Bay Traveler Mainframe for TM5000 Series System D1

$99.99



Fluke Networks Versiv Modular Mainframe AS IS picture

Fluke Networks Versiv Modular Mainframe AS IS

$1100.00



Tektronix 7904 Oscilloscope Mainframe  w/ 2x 7A26 2x 7B92A Modules picture

Tektronix 7904 Oscilloscope Mainframe w/ 2x 7A26 2x 7B92A Modules

$399.97



Chroma 6312 DC Electronic Load Mainframe  picture

Chroma 6312 DC Electronic Load Mainframe

$239.96







Copyright © 2004-2016 BlackBerryForums.com.
The names RIM © and BlackBerry © are registered Trademarks of BlackBerry Inc.