开发者

BlackBerry: Duplicate application menu items in UiApplication

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. ApplicationMenuItemReposi开发者_开发问答tory 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.


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.


Use the removeMenuItem() method when the user exits your application. it will work.

if(_serverMenuItem != null) {
    ApplicationMenuItemRepository.getInstance().
    removeMenuItem(ApplicationMenuItemRepository.MENUITEM_PHONE,_serverMenuItem);
}


If you want to add custom menu fields to native applications you can use a RunTime store to register you menu item and then check for it while you re-run your code :

ApplicationMenuItem ami = new ApplicationMenuItem(placement); // some placement you want     to use e.g 0x35090
ApplicationMenuItemRepository amir = ApplicationMenuItemRepository.getInstance();
    RuntimeStore store = RuntimeStore.getRuntimeStore(); // get the store instance

    if(store.get(ApplicationMenuItemRepository.MENUITEM_CALENDAR) == null)// if object is not added only then add the item to the menu
    {
        try 
        {
            store.put( ApplicationMenuItemRepository.MENUITEM_CALENDAR, ami );
        } 
        catch(IllegalArgumentException e){}
        amir.addMenuItem(ApplicationMenuItemRepository.MENUITEM_CALENDAR, ami);
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜