tags:

views:

29

answers:

1

I have a BlackBerry UiApplication, which registers some menu items in the standard Phone and Contacts applications. I need the menu items to be registered on phone startup, ie, before my UiApplication is started.

I can achieve this if I configure my UiApplication to auto-run on startup, and register the menu items in my app initialisation code using ApplicationMenuItemRepository.

My problem is that every time my UiApplication is subsequently opened, my initialisation code is run again, and I get duplicate menu items in the Phone and Contacts app. ApplicationMenuItemRepository does not provide an API to check if they are already registered. Using a static boolean in my own code also does not help, presumably because different classloaders are used for each app instance.

Am I using the wrong approach here? Should I have a separate Application (to register Phone/Contacts menu items) and UiApplication (for my views)? That feels overly complex for my needs.

+2  A: 

Use the Alternate Entry Point

  1. Click on the project node.

  2. Right click and select Properties.

  3. In the Properties window, select the Application tab.

  4. Ensure the following options are checked: Auto-run on startup and System module (to register the thread with the system).

  5. Create another project under the same folder as the original project. Right click on the new project node and select Properties.

  6. Select the Application tab and select Alternate CLDC Application Entry Point from the Project type drop down menu. As shown in the attached file, select the name of the original project (for example: trafficreporter) from the Alternate entry point for drop down menu. Also specify the arguments that would launch the application using this alternate entry point (for example: gui).

  7. 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 } } }

  8. Add your application iconfile to the this new "Entry Point" application and make it the ribbon icon.

Michael B.