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)

gs
simon


Code:
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();
			app.enterEventDispatcher();
		} else {
			String appToLaunch = args[0];
			if (ARG_LAUNCH_EXPLORER_EXTENSION.equals(appToLaunch)) {
				System.out.println("launched");
			}
			
		}
	}

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

	private static void addMenuItem(String argOfAppl, long location,
			ApplicationMenuItem applMenuItem) {
		ApplicationMenuItemRepository amir = ApplicationMenuItemRepository
				.getInstance();
		ApplicationDescriptor app = ApplicationDescriptor
				.currentApplicationDescriptor();
		app = new ApplicationDescriptor(app,
				new String[] { ARG_LAUNCH_EXPLORER_EXTENSION });
		amir.addMenuItem(location, applMenuItem, app);
	}

	private static class DemoMenuItem extends ApplicationMenuItem {
		DemoMenuItem() {
			super(20);
		}

		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
Offline  
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

OEM BULB with Housing for DELL 7700 FullHD Projector with 180 Day Warranty
$319.0
OEM BULB with Housing for DELL 7700 FullHD Projector with 180 Day Warranty picture21.5inch OEM Dell Inspiron 2205 WLED LCD Panel LTM215HT03 6JT5P
$139.0
21.5inch OEM Dell Inspiron 2205 WLED LCD Panel LTM215HT03 6JT5P picture21.5inch LCD Panel LTM215HT03 6JT5P OEM Dell Inspiron 2205 WLED
$139.2
21.5inch LCD Panel LTM215HT03 6JT5P OEM Dell Inspiron 2205 WLED picture1PCS LTM215HT03 6JT5P OEM Dell Inspiron 21.5inch LCD Panel 2205 WLED
$139.8
1PCS LTM215HT03 6JT5P OEM Dell Inspiron 21.5inch LCD Panel 2205 WLED picture1PCS 21.5inch LCD Panel LTM215HT03 6JT5P OEM Dell Inspiron 2205 WLED
$139.5
1PCS 21.5inch LCD Panel LTM215HT03 6JT5P OEM Dell Inspiron 2205 WLED picture






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