The BlackBerry architecture allows applications to
be started automatically in the background by the system without
requiring the user to explicitly initialize them. This allows application
threads to always run in the background with no user interface component.
Alternate Entry Points can be used to launch the user interface
(UI) component of the auto-started application when the user selects
the icon from the ribbon. This feature allows application threads
to be launched in the background that can be used for actions like
listening for incoming push messages, pre-processing data, or initializing network
communications with a server host.
After creating the projects for the original application,
you will have to create another project for the UI entry point.
Assuming that the thread to be run exists in the same project as
the original application, follow these steps:
- Right-click the project node and select Properties.
- In the Properties window, select the Application tab.
- Verify the following options are checked: Auto-run
on startup and System module (to register the
thread with the system).
- Create another project under the same folder as the original
project. Right-click the new project node and select Properties.
- Select the Application tab and select Alternate
CLDC Application Entry Point from the Project type drop-down
list. As shown in the attached file, select the name of the original
project (for example, trafficreporter) from the Alternate
entry point for drop-down list. Also specify the arguments
that would launch the application using this alternate entry point
(for example:
gui).
- Modify the main() method of the original project as follows:
public static void main(String[] args) {
if ( args != null && args.length > 0 && args[0].equals("gui")
){
// code to initialize the app
theApp.enterEventDispatcher();
} else {
// code to launch the background thread }
}
}
- Add your application icon file to the this new entry point
application and make it the ribbon icon.
The entry point application now consists only of an application
icon and a parameter to pass to the main() method of the main application.
There is no source code associated with this project. The main application
contains all of the source code, including the thread to be started
automatically.
Now, whenever the device is started, this main() method will
be executed without any arguments, and the background thread will
start. When the application icon is clicked from the main ribbon,
the main() method will be executed with the argument specified in
the above code sample ("gui") and the application can
pop a screen to the foreground.