Troubleshooting guide
89
4: Managing data
Activate synchronization when the BlackBerry device starts
Code sample: Letting the BlackBerry Desktop Software back up and restore
application data
Example: RestaurantsSync.java
/**
* RestaurantsSync.java
* Copyright (C) 2001-2005 Research In Motion Limited. All rights reserved.
*/
Task Steps
Activate synchronization when the
BlackBerry® device starts.
The first time the BlackBerry device starts, the Alternate CLDC Application Entry Point project
passes an argument to the application so that the application registers only once.
> In the main method of the application, create code that activates the synchronization process.
public static void main(String[] args) {
boolean startup = false;
for (int i=0; i<args.length; ++i) {
if (args[i].startsWith("init")) {
startup = true;
}
}
if (startup) {
//enable application for synchronization on startup
SerialSyncManager.getInstance().enableSynchronization(new
RestaurantsSync());
} else {
RestaurantsSync app = new RestaurantsSync();
app.enterEventDispatcher();
}
}
Create a project that acts as an
alternate entry point to the main
application.
If the application is a MIDlet, arguments cannot pass to the application when the BlackBerry device
starts.
1. In the BlackBerry Integrated Development Environment, create a project.
2. Right-click the project, and then click Properties.
3. Click the Application tab.
4. In the Project type drop-down list, click Alternate CLDC Application Entry Point.
5. In the Alternate entry point for drop-down list, click the project that implements
synchronization.
6. In the Arguments passed to field, type init. Make sure that the value you type in the Arguments
passed to field matches the value in the startsWith argument in the main method of the
application.
7. Select the Auto-run on startup option.
8. Select the System module option.
9. Click OK.