BlackBerry Forums Support Community               

Closed Thread
LinkBack Thread Tools
Old 11-12-2007, 10:38 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
Closed Thread

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

VENTURE LIGHTING CORE & COIL HALIDE BALLAST KIT 250W 120-277V V90D6211K picturesylvania mb2 x 40/277 rs magnetic ballast
sylvania mb2 x 40/277 rs magnetic ballast picturePhilips Dimmable Electronic Ballast IZT-2S54-D
Philips Dimmable Electronic Ballast IZT-2S54-D pictureRobertson L6827 Simple Reactance Ballast, F4,F6 or F8 Lamp
Robertson L6827 Simple Reactance Ballast, F4,F6 or F8 Lamp  picture2-3 Lamp T8 F32 Fluorescent Ballast Lot - brand new 332BIS/UV/HE 120-277 Volt
2-3 Lamp T8 F32 Fluorescent Ballast Lot - brand new 332BIS/UV/HE 120-277 Volt picture

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