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
ingvar_e
Posts: 551
Registered: ‎10-31-2009
My Device: Torch 9800, Bold 9700
My Carrier: Movistar, Telenor
Accepted Solution

Follow up question on Listeners

Is it possible to structure listeners like this:

 

 a lister that is just a class. It uses Global Events to commincate pertinent information

 

Does not have a static Main and does not register itself. just have the entrypoints neded

 

A startup App  instantiates the listener and also registers the listener

 

It seems like a clean and logical way of doing it but I have a suspicion that it does not work. Something about

 

"The app that registers is the receiver" or something like that

If everything seems to be under control, you're just not driving fast enough
-Mario Andretti-
Please use plain text.
Developer
simon_hain
Posts: 15,846
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: Follow up question on Listeners

i usually use an autostart entry point to register listeners. in most cases they communicate using global events (or launch the app using ApplicationManager if it is not running)
----------------------------------------------------------
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
Please use plain text.
Developer
peter_strange
Posts: 19,598
Registered: ‎07-14-2008
My Device: Not Specified

Re: Follow up question on Listeners

Agree with Simon.

 

Note that most listeners don't need an Application in order to be registered, but some do, for example SystemListener.  In these cases, the approach will not work.  For these, I normally start the application in the background because an alternate entry point can cause grief.  But it works really well when just inserting listeners. 

 

Can we use the term "interface" rather than "entrypoint"?

Please use plain text.
Developer
ydaraishy
Posts: 562
Registered: ‎09-30-2009
My Device: Not Specified

Re: Follow up question on Listeners

[ Edited ]

If you have no main method, ie., no entry point, where is the listener class instantiated? You mention a startup application -- when is the application started, and where does the flow of execution start from in that startup application?

 

I think you can definitely have single classes as listeners, but you cannot expect them to work completely in isolation -- it must belong to a process, ie., be instantiated from a full-fledged application.

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

Re: Follow up question on Listeners

ydaraishy - I read that and was confused too.  Read it again and you will see the OP states there is no static main in the Listener....

Please use plain text.
Developer
ingvar_e
Posts: 551
Registered: ‎10-31-2009
My Device: Torch 9800, Bold 9700
My Carrier: Movistar, Telenor

Re: Follow up question on Listeners

OK to clarify my idea

 

this is the startup app where I want  to get the phonelistener going

 

import listener.Listener;
import net.rim.blackberry.api.phone.Phone;
import net.rim.device.api.system.Application;

public class ThreadBlackBerry extends Application
{
    public static void main(String args[])
      {
         Listener listen;
         listen = new Listener();
         Phone.addPhoneListener(listen);     //Register phoione listener
     }
}

 

And this is my listener where I commented out the part that is the register part:

 

public final class Listener extends Thread implements PhoneListener
{   
 // public static void main(String args[])
 //  {
 //   Listener.registerOnStartup();           //Register this as a Phone Listener
 //  }
 // static private void registerOnStartup()   
 //  {
 //   phone_handler = new Listener();
 //   Phone.addPhoneListener(phone_handler);
 //  }
   public void callInitiated(int callid)

If everything seems to be under control, you're just not driving fast enough
-Mario Andretti-
Please use plain text.
Developer
simon_hain
Posts: 15,846
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: Follow up question on Listeners

yes, this approach works. usually you don't want a second app only for the listener, this is why we suggested alternate entry points.
----------------------------------------------------------
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
Please use plain text.
Developer
ingvar_e
Posts: 551
Registered: ‎10-31-2009
My Device: Torch 9800, Bold 9700
My Carrier: Movistar, Telenor

Re: Follow up question on Listeners

Reason I started out on this approach is that it suits best when making a transition from the current architecture. This time I will not close this thread until I have tested  :-)

If everything seems to be under control, you're just not driving fast enough
-Mario Andretti-
Please use plain text.