BlackBerry Forums Support Community
              

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

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

New OEM IBM 1372475 Pageprinter 3130 Fuser 100v
$0.99
New OEM IBM 1372475 Pageprinter 3130 Fuser 100v pictureNew OEM Genuine IBM 57P5709 Black Toner Cartridge SEALED
$0.99
New OEM Genuine IBM 57P5709 Black Toner Cartridge SEALED  pictureNew OEM IBM 70X7442 3930 PagePrinter Cleaning Unit
$0.99
New OEM IBM 70X7442 3930 PagePrinter Cleaning Unit pictureNew OEM IBM 1402683 Infoprint 60 / 3160 Cleaning Kit
$0.99
New OEM IBM 1402683 Infoprint 60 / 3160 Cleaning Kit pictureNew OEM IBM 44D7279 Infoprint 4100 toner cartridge
$0.99
New OEM IBM 44D7279 Infoprint 4100 toner cartridge picture






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