05-10-2010 05:32 AM
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
Solved! Go to Solution.
05-10-2010 05:56 AM
05-10-2010 06:20 AM
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"?
05-10-2010 06:25 AM - edited 05-10-2010 06:28 AM
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.
05-10-2010 07:39 AM
OK to clarify my idea
this is the startup app where I want to get the phonelistener going
public class ThreadBlackBerry extends Application
public static void main(String args)
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();
public void callInitiated(int callid)
05-10-2010 07:42 AM
05-10-2010 08:29 AM
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 :-)