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

CUTLER HAMMER CONTACTOR 200 AMP, 600V, 3 POLE -- 120V COIL -- MODEL: C832KN3
$189.99
CUTLER HAMMER CONTACTOR 200 AMP, 600V, 3 POLE -- 120V COIL -- MODEL: C832KN3 pictureALLEN BRADLEY 509-TOD NEW NO BOX SIZE 00 208V COIL STARTER SEE PICS #B20
$40.0
ALLEN BRADLEY 509-TOD NEW NO BOX SIZE 00 208V COIL STARTER SEE PICS #B20 pictureCUTLER HAMMER CE12CNC301T2 IEC 3P CONT 24VDC LOW VA COIL W/1NC AUX --SES
$67.13
CUTLER HAMMER CE12CNC301T2  IEC 3P CONT 24VDC LOW VA COIL W/1NC AUX --SES pictureCUTLER HAMMER CE52CNC301B IEC 3P REV CONT 240VAC COIL W/1NC AUX --SES
$103.13
CUTLER HAMMER CE52CNC301B  IEC 3P REV CONT 240VAC COIL W/1NC AUX  --SES pictureCUTLER HAMMER CE12CNP310T IEC 3P CONT 24VAC COIL W/1NO AUX --SES
$67.13
CUTLER HAMMER CE12CNP310T IEC 3P CONT 24VAC COIL W/1NO AUX  --SES picture






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