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

New Contributor
Posts: 4
Registered: ‎10-07-2010
My Device: Blackberry 9550
My Carrier: Airtel

How to add addGlobalEventListener in a class in blackberry?

I have made one multiEntry point application where App2 is autorun and App1 runs on click Trying to invoke a global event from app1,to do some task in app2.Can anybody help to figure out where am going wrong?

 public class App2  implements GlobalEventListener{
        static public int counter = 0;
        public static final long RTSID_MY_APP = 0x7451402f595f81a5L;
        public static final long contId = 0x1251402f595f81a5L;
        public static final long eventId=0xba4b84944bb7429eL;
        private App2() {            

         public static App2 waitForSingleton()
            RuntimeStore store = RuntimeStore.getRuntimeStore();
            Object obj = store.get(RTSID_MY_APP);
   if (obj == null)
   store.put(RTSID_MY_APP, new App2());
   return (App2)store.get(RTSID_MY_APP);
            } else
              return (App2)obj;

        public void eventOccurred(long guid, int data0, int data1, Object object0,
                Object object1) {

 Then in other class I tried like


public class App1 extends MainScreen  {
    static public int counter = 0;
    public static final long eventId=0xba1b84944bb7429eL;

     public App1() {

protected void makeMenu(Menu menu, int instance) { 
    super.makeMenu(menu, instance); 
    menu.add(new MenuItem("Call", 20, 10) { 
        public void run() { 
            RuntimeStore store = RuntimeStore.getRuntimeStore();
            Object obj = store.get(App2.RTSID_MY_APP);
            add(new RichTextField("Event Recived#counter#"+App2.counter));

 But all the time output is same

Event Recived#counter#0


which I guess suggests that object for App2 in not null but eventOccurred never invoked.


BlackBerry Development Advisor
Posts: 15,857
Registered: ‎07-09-2008
My Device: BlackBerry PRIV
My Carrier: Bell

Re: How to add addGlobalEventListener in a class in blackberry?

You'll need to extend UiApplication and Application to create a complete application.  This example should help you out.


Global Events and Global Event Listeners


Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.