BlackBerry Forums Support Community

Closed Thread
LinkBack Thread Tools
Old 11-12-2007, 09:36 AM   #1 (permalink)
CrackBerry Addict
Join Date: Apr 2005
Location: hamburg, germany
Model: 8900
Carrier: o2
Posts: 838
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default creating a menu item in another application

Please Login to Remove!

while the sample from the developer labs does not work for me the one from the developer guide (p.42) works like a charm.

With the exception that it does not work the way it should.
i'll post the whole code and refer to it beforehand. The sample is unchanged in all but name, place of the menu item (explorer instead of contacts) and the run method of the menuitem.

According to both the comments in the sample and the API documentation the run-method of the class DemoMenuItem should be executed when you click the menu entry. The context of the menu, read the clicked item, is given as a parameter.

What happens now is:
The code behind the alternate application entry point, System.out.println("launched"), is executed.
The code in the run method, System.out.println("run is running"), is not.
A breakpoint in the run method is never reached while the toString-method is called.

It is great that i can start an application (or anything) from my own menu item. But i'd like to manipulate the item i am clicking on, in this case a file in the explorer view. That's what the context is for, but without execuing the run method i am unable to get it.

I hope somebody who already used this sample can help me along despite my lengthy post.

(and everybody else can speculate why RIM calls system.exit in a constructor and enters the event dispatcher afterwards...)


import net.rim.blackberry.api.menuitem.ApplicationMenuItem;
import net.rim.blackberry.api.menuitem.ApplicationMenuItemRepository;
import net.rim.device.api.system.Application;
import net.rim.device.api.system.ApplicationDescriptor;

public final class MenuTest extends Application {
	private static final String ARG_LAUNCH_EXPLORER_EXTENSION = "1";

	public static void main(String[] args) {
		if (args == null || args.length == 0) {
			MenuTest app = new MenuTest();
		} else {
			String appToLaunch = args[0];
			if (ARG_LAUNCH_EXPLORER_EXTENSION.equals(appToLaunch)) {

	MenuTest() {
		long locationToAddMenuItem = ApplicationMenuItemRepository.MENUITEM_FILE_EXPLORER_BROWSE;
		addMenuItem(ARG_LAUNCH_EXPLORER_EXTENSION, locationToAddMenuItem,
				new DemoMenuItem());

	private static void addMenuItem(String argOfAppl, long location,
			ApplicationMenuItem applMenuItem) {
		ApplicationMenuItemRepository amir = ApplicationMenuItemRepository
		ApplicationDescriptor app = ApplicationDescriptor
		app = new ApplicationDescriptor(app,
		amir.addMenuItem(location, applMenuItem, app);

	private static class DemoMenuItem extends ApplicationMenuItem {
		DemoMenuItem() {

		public String toString() {
			return "This is my little menu item";

		public Object run(Object context) {
			System.out.println("run is running");
			return context;
java developer, Devinto, hamburg/germany

Copyright 2004-2016
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.