08-01-2008 11:57 AM
I am trying to add a custom menu item to the Blackberry message application, and get two issues:
Application.getApplication().requestForeground()
to
ApplicationManager.getApplicationManager().runApplication(app); // Where app is the application descriptor of "DemoMI"
The main() method will be called. However, how can I pass the Message object around from within the "run" method to the intended application "com.demo.DemoApp"? I was trying to use a static variable "ContactsDemoMenuItem mi", but I always got "null" as the value when the "main()" is called.
My environment:
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.*; import net.rim.blackberry.api.mail.Message; import net.rim.device.api.ui.UiApplication; import net.rim.device.api.ui.*; import net.rim.device.api.ui.component.*; import net.rim.device.api.ui.container.*; public final class DemoMI extends Application { private static final String ARG_LAUNCH_CONTACT_DEMO = "1"; private static ContactsDemoMenuItem mi; public static void main(String[] args) { if(args == null || args.length == 0) { DemoMI app = new DemoMI(); app.enterEventDispatcher(); }else { String appToLaunch = args[0]; if(ARG_LAUNCH_CONTACT_DEMO.equals(appToLaunch)) { new com.demo.DemoApp(mi.getMessage()).enterEventDispat
cher(); } } } DemoMI() { long locationToAddMenuItem = ApplicationMenuItemRepository.MENUITEM_EMAIL_VIEW ; ApplicationMenuItemRepository amir = ApplicationMenuItemRepository.getInstance(); ApplicationDescriptor app = ApplicationDescriptor.currentApplicationDescriptor (); app = new ApplicationDescriptor(app, new String[]{ARG_LAUNCH_CONTACT_DEMO}); mi = new ContactsDemoMenuItem(app); amir.addMenuItem(locationToAddMenuItem, mi); System.exit(0); } private static class ContactsDemoMenuItem extends ApplicationMenuItem { ApplicationDescriptor app; Message msg; ContactsDemoMenuItem(ApplicationDescriptor app) { super(20); this.app = app; } public String toString() { return "My Menu Item"; } public Message getMessage() { return msg; } public Object run(Object context) { if ( context instanceof Message ) { msg = (Message)context; try { Application.getApplication.requestForeground(); //ApplicationManager.getApplicationManager().runAp plication(app); }catch(Exception e) { e.printStackTrace(); } } else { throw new IllegalStateException( "Context is null, expected a Contact instance"); } return null; } } }
Solved! Go to Solution.
08-01-2008 02:46 PM
What you are seeing is the expected behaviour. The ApplicationMenuItem is running in a different process from where your application was run. You have a couple of options.
You could store the Message object in the RuntimeStore when the ApplicationMenuItem is invoked. Your application that you are starting could then read the Message object from the RuntimeStore.
Or you could create an application based on the design shown here:
How To - Allow a background listener to detect and update a GUI application