Welcome!

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

Reply
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() {            
              Application.getApplication().addGlobalEventListener(this);            
        }

         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) {
             if(guid==eventId){
                counter++;
            }               
        }
    }

 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);
            if(obj!=null)
            add(new RichTextField("Event Recived#counter#"+App2.counter));
            ApplicationManager.getApplicationManager().postGlobalEvent(App2.eventId);
        } 
    });          
}
}

 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,727
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

http://supportforums.blackberry.com/t5/Java-Development/Global-Events-and-Global-Event-Listeners/ta-...

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker