Troubleshooting guide

37
1: Creating UIs
Code sample: Creating a new menu item in a BlackBerry application
The menu item appears when a BlackBerry® device user views a contact in the address book. When a BlackBerry
device user clicks the menu item, the ContactsDemo application appears.
Example: DemoAppMenuItem.java
/**
* DemoApplicationMenuItem.java
* Copyright (C) 2003-2007 Research In Motion Limited.
*
* The following code example creates a menu item that appears when
* a user views a contact in the address book. When a user clicks the menu item,
* the Contacts Demo application appears.
*/
package com.rim.samples.docs.menuitem;
import net.rim.device.api.system.*;
import net.rim.device.api.ui.component.Dialog.*;
import net.rim.blackberry.api.menuitem.*;
import net.rim.blackberry.api.pdap.*;
import javax.microedition.pim.*;
public final class DemoAppMenuItem extends Application
{
private static final String ARG_LAUNCH_CONTACT_DEMO = “1”;
//private static final String ARG_LAUNCH_APP2 = “2”;
//... etc
public static void main(String[] args) {
if(args == null || args.length == 0)
{
DemoAppMenuItem app = new DemoAppMenuItem();
app.enterEventDispatcher();
}
else
{
String appToLaunch = args[0];
if(ARG_LAUNCH_CONTACT_DEMO.equals(appToLaunch))
{
new
com.rim.samples.docs.contactsdemo.ContactsDemo().enterEventDispatcher();
}
//add more else ifs here
}
}