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
Developer
Posts: 85
Registered: ‎02-13-2009
My Device: 9860
My Carrier: MTS
Accepted Solution

GlobalEventListener not working?

Hi!

I use GlobalEventListener with eventOccurred() method. I use it for changeing of application icon. But seems it does not work on phone (worked fine on the emulator), actually, the method eventOccured will nerver be called! Why? Has anyone meet this problem before?

Please, help :smileysad:

Thanks in advance!

Developer
Posts: 85
Registered: ‎02-13-2009
My Device: 9860
My Carrier: MTS

Re: GlobalEventListener not working?

Any ideas? I am realy confused ... It is not worked on device. Have anybody same issues???
Developer
Posts: 16,651
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: GlobalEventListener not working?

any special it policies? is process communication allowed for your app?
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 85
Registered: ‎02-13-2009
My Device: 9860
My Carrier: MTS

Re: GlobalEventListener not working?

Hi simon_hain !

How can I know is process communication allowed for my app? What you mean?

I use ApplicationManager.postGlobalEvent(long guid) method to make event. It is marked by "lock icon". I have my applicaton signed 

and this method return "true"... But eventOccurred was never called on device(it is not marked to be signed)...I don't know - why it is not works..

Thanks for your help!

Developer
Posts: 19,624
Registered: ‎07-14-2008
My Device: Not Specified

Re: GlobalEventListener not working?

Have you done any on device debugging to determine where the problem is?  It could be an Exception in the post, the fact that the event is not received, or an exception in the processing. 
Developer
Posts: 85
Registered: ‎02-13-2009
My Device: 9860
My Carrier: MTS

Re: GlobalEventListener not working?

Hi Peter! There is my function which posts event:

 

public void messagesAdded(FolderEvent e)
{
   try   
   {
       Message msg = e.getMessage();
       if(NotificationParser.IsValid(msg))   
       {
            Notification notification = NotificationParser.Parse(msg);
            NotificationStorage.getInstance().addNew(notification);
            Mail.RemoveMessage(msg);

            Object label = RuntimeStore.getRuntimeStore().get(APP_ID);
            if(label == null)
            {

                  Debug.Log("label == null ");
                  boolean res = ApplicationManager.getApplicationManager().postGlobalEvent(0x7d3a74a5ccfe6111L);

                  if (res == true)

                  {

                       Debug.Log("res == true"); 

                  } 

            }


            Debug.Log("play sound"); 

            Utils.startNotification(true);
       }
    }
    catch(Exception ex)
    {
           Debug.Log("<NotificationListener.messagesAdded> Error ", ex);
    }
}

 In log I can see : label == null

                          res == true

                          play sound 

..and there is no exception.... but first called function in eventOccured method is Debug.Log("Event!") was never called.....

Developer
Posts: 19,624
Registered: ‎07-14-2008
My Device: Not Specified

Re: GlobalEventListener not working?

What I would do next is create a very small UI app, that started a GlobalEventListener and displayed the GUID of any GlobalEvents it received.

 

My suspicion now is that the Application that you registered your GlobalEventListener using is no longer around. 

Developer
Posts: 85
Registered: ‎02-13-2009
My Device: 9860
My Carrier: MTS

Re: GlobalEventListener not working?

Perhaps, you are right...

Here is my code. I have two entry points. Can you find my error? What wrong?

 

public final class Program extends UiApplication implements GlobalEventListener

{

     private Program( boolean autoStart)

     {

         Utils.SetIcons();

         if (autoStart)

         {

               NotficationFacade.AttachNotificationListener();

         } else

         {

               try {

                         UIFacade.InitializeUI();

                         UIFacade.ShowMainScreen();

                    }

             catch(Exception ex)

             {

                       Debug.Log("<Program.UIFacade.ShowMainScreen>", ex);

             }

         }

     }

 

   public static void main(String[] args)

   {

      try

      {

           try

           {

                   NotficationFacade.InitializeNotificationsLibrary();

                   EventLogger.register(Debug.LOG_KEY, "MyClient", EventLogger.VIEWER_STRING);

                   Program app=null;

 

                   if( args != null && args.length > 0 && args[0].equals("gui") )

                   {

                        app = new Program(false);

                   }

                  else

                  {

                               app = new Program(true);

                               app.addGlobalEventListener(app);

                  }

 

                 if(app!=null)

                 {

                      app.enterEventDispatcher();

                 }

              }

             finally

            {

                 NotficationFacade.UninitializeNotificationsLibrary();

             }

       }

       catch(Exception ex)

       {

                Debug.Log("<Program.main>", ex);

        }

     }

 

 

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

     {

          try {

                Debug.Log("Event!");

                if(guid == 0x7d3a74a5ccfe6000L)

                {

                            UiApplication.getUiApplication().invokeLater(new Runnable()

                            { public void run()

                                      {

                                                 Utils.SetIcons();

                                      }

                             });

                 } else if(guid == 0x7d3a74a5ccfe6111L)

                 {  

                           UiApplication.getUiApplication().invokeLater(new Runnable()

                           { public void run()

                                    {

                                                Utils.SetUnreadIcons();

                                    }

                            });

                 }

               }

              catch(Exception ex)

              {

                       Debug.Log("<Program.eventOccurred>", ex);

              }

      }

}  

 

For both cases (autostart and manually start)  it is used enterEventDispatcher()... seems it is incorrect...What do you think about it?

Developer
Posts: 85
Registered: ‎02-13-2009
My Device: 9860
My Carrier: MTS

Re: GlobalEventListener not working?

I made separate application which waits for global events and this application can see event which I post on new message.

So, when my application is startup automatically(first entry point without gui), it is have class which implements FolderListener to catch messages. 

On new message it is post global event but this event it can't to see... If I understand right, if I call enterEventDispatcher(), then my application is not closed... I am realy confused ((( and it is works on emulator.... 

Developer
Posts: 19,624
Registered: ‎07-14-2008
My Device: Not Specified

Re: GlobalEventListener not working?

It seems likely that your 'start-up' application is not starting correctly or not staying alive. 

 

You say it works on the Simulator and doesn't work on the device.  There are two common problems that cause this

a) Wrong level of JDE/Component Pack.  To check this can you confirm that the OS of your JDE/Component pack is less than or the same as the device

b) Security, the app is attempting to do something that it is not allowed to do.

 

In either case you should see something in the log at startup time if there is an error.  In fact I would suggest that you do some logging into there, as your startup application proceeds.  It seems that the start-up actually does work because the folder listener is registered.  However this listener will work, even if the application terminates. 

 

Now the interesting thing here is that both your startup and your GUI application are UiApplications.  That means you will see them when you do a Task Switch.  So when your GUI is active, and you do a task switch, you should see two of your icons.  Do you?  If you don't, it probably means that you background processing has terminated.  You need to find out why.  Since you should already have looked for Exceptions in the log, look for places that you deliberately call System.exit(nn).

 

Good luck.