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
bill_zj
Posts: 49
Registered: ‎10-09-2008
My Device: Not Specified
Accepted Solution

Launch Global Event Listener when auto start myapp

What I was trying to do:

 

Myapp has an alternative entry point and GUI interface.

from alternative entry, I wanto register a folderlistener which fires a global event in order to trigger an email sending process.

 

so far, I only got the whole process running only if I register the Global Event listener in the GUI part, that means when myapp GUI showed up then Global Event listerner worked,

 

but I want Global Event listener stays all the time, how can I do that?

 

I've done some search in this fourm but just could not figure it out:Sweatdrop:

 

any reply appreciated.

 

my code:

 

============================================

public  class MyApp extends UiApplication implements FieldChangeListener,GlobalEventListener
{

 public static  void main(String[] args)  throws AddressException, ClassNotFoundException
    {
        MyApp theApp;
        //if( args != null && args.length > 0) {
        if(    args.length > 0 && args[0].equals("Auto-MyApp")) {
          
          //Entered through the alternate application entry point.
            //Enable folderlistener on startup.
            FolderListenerApp.waitForSingleton();
           
        }
        else {
            theApp = new MyApp();      
                theApp.enterEventDispatcher();
        }
     
    }



   private   void AddGlobalEvent() {
        addGlobalEventListener((GlobalEventListener) this) ;
    }
   

   
  public MyApp() throws AddressException, ClassNotFoundException
    {       
       
    ........

       
    AddGlobalEvent();
       
       
    ........       
       
   
     }

public void eventOccurred(long guid, int data0, int data1, Object object0,
            Object object1) {
       
        Logger.logEventError("in eventOccurred...");
           //Is this the GlobalEvent we are waiting for?
          
           if (guid == 0xa4c7e78a6c3fe109L)
           {
               //Yes it is.

               FolderListenerAction  fa = new FolderListenerAction();
                  new Thread(fa).start();
           }
       
    }

}

 

==================================

 

Please use plain text.
Developer
jhw1701
Posts: 176
Registered: ‎11-06-2008
My Device: Not Specified

Re: Launch Global Event Listener when auto start myapp

[ Edited ]

Check out this tutorial I posted a while back, it shows an app that's split into a background process (extends Application and starts when the OS boots up) and a foregroud/UI process (extends UiApplication).

 

Both are implementing GlobalEventListener and use that to talk with each other

 

http://supportforums.blackberry.com/t5/Java-Development/Tutorial-Communicate-between-apps-processes/...

 

scroll down to the post with this date "06-19-2010 11:22 PM " to the get the fixed version of the code

 



Please use plain text.
Developer
bill_zj
Posts: 49
Registered: ‎10-09-2008
My Device: Not Specified

Re: Launch Global Event Listener when auto start myapp

thanks, I'll get it a try
Please use plain text.
Developer
bill_zj
Posts: 49
Registered: ‎10-09-2008
My Device: Not Specified

Re: Launch Global Event Listener when auto start myapp

it worked!
thank you very much for your instructions.

Please use plain text.
Developer
bill_zj
Posts: 49
Registered: ‎10-09-2008
My Device: Not Specified

Re: Launch Global Event Listener when auto start myapp

Hi jhw1701,

The Global Event Listener was launched by the alternative entry, but it only worked for awhile about a couple of hrs then it stopped working, it works again if I reboot the BB but again for awhile.

 

Appreciated any thoughts about this .

Please use plain text.
Developer
jhw1701
Posts: 176
Registered: ‎11-06-2008
My Device: Not Specified

Re: Launch Global Event Listener when auto start myapp

Without posting your code I can only guess.

 

Make sure you do not exit or terminate the background process. In other words make sure the background process never calls System.exit( ).

Please use plain text.
Developer
bill_zj
Posts: 49
Registered: ‎10-09-2008
My Device: Not Specified

Re: Launch Global Event Listener when auto start myapp

Fixed! Thank you very much, jhw1701.

 

there was a System.exit() hiden in a class.

 

Bill

Please use plain text.
Developer
rajani_dhawan
Posts: 55
Registered: ‎05-30-2011
My Device: BlackBerry torch 9800
My Carrier: Airtel

Re: Launch Global Event Listener when auto start myapp

For auto startup- you can see main functions of "MyApp: class on the given following link.

 

Please can any one help....how to restrict the invocation of BB applications when they come to startup.

 

My link is:

http://supportforums.blackberry.com/t5/Java-Development/global-event-listener-is-not-called-instantl...

 

Please use plain text.
Developer
peter_strange
Posts: 19,601
Registered: ‎07-14-2008
My Device: Not Specified

Re: Launch Global Event Listener when auto start myapp

[ Edited ]

@rajani_dhawan: This Thread is not related to your problem.  This is about starting a Listener, not about what the listener detects.  No answer here sorry. 

Please use plain text.