Tuesday, January 27, 2009

Code : Allow an application to restart itself


A Java application for a BlackBerry device is able to shut down and restart itself. Prior to exiting, the application should stop all threads and free up resources. The following code shows a simple application that will continuously exit and restart itself.







public final class RestartSample extends Application {

public static void main(String[] args) {


RestartSample theApp = new RestartSample();


theApp.enterEventDispatcher();


}


public RestartSample() {


System.out.println(“Application Started…”);


//Get the current application descriptor.


ApplicationDescriptor.currentApplicationDescriptor();


System.out.println(“Scheduling the restart in 1 minute…”);


/* Schedules are rounded to the nearest minute so ensure the application is scheduled for at least 1 minute in the future.*/


ApplicationManager.getApplicationManager


().scheduleApplication(current,


System.currentTimeMillis() + 60001, true);


System.out.println(“Application is exiting…”);


System.exit(0);


}


}

No comments:

Post a Comment

Place your comments here...