Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Add a custom menu item to an existing BlackBerry application

by Retired ‎02-12-2010 04:30 PM - edited ‎02-17-2010 11:33 AM (13,200 Views)


This article applies to the following:

  • BlackBerry® Java® Development Environment (BlackBerry JDE)
  • BlackBerry smartphones based on Java technology


The ApplicationMenuItem class will allow the addition of a custom menu item to various screens within BlackBerry specific applications, or as a system-wide setting. The following example illustrates how to add a menu item to the email view screen.

Obtain an instance of the MenuItemRepository to add the menu item.

MyMenuItem myMenuitem = new MyMenuItem(0);


Create a class so that certain methods within the ApplicationMenuItem class can be overridden.

class MyMenuItem extends ApplicationMenuItem{

//using the default constructors here.
MyMenuItem(int order){

//methods we must implement
//Run is called when the menuItem is invoked
public Object run(Object context){
//context object should be a email message
if (context instanceof Message){
Message message = (Message)context;
//this is where we would work the message
//do something here
return context;

//toString should return the string we want to
//use as the lable of the menuItem
public String toString(){
return "MyMenu Name";

It should be noted that Object context that is passed into the run method will depend on the screen to which the menu item has been added. In this example, the context is an email message because the menu item has been added to the email view screen. If the item was added to the address book, it would return a personal information management (PIM) item.

Additional Information

Users Online
Currently online: 48 members 1,624 guests
Please welcome our newest community members: