On Tue, Sep 7, 2010 at 4:09 AM, KrcK --- <[email protected]> wrote: > I would like to know what are the main differences between TelephonyManager > and PhoneStateListener, because you can do (more or less) the same things > with both.
There is a bit more to TelephonyManager than just monitoring phone state. > For example, you could create an incoming calls register implementing a > broadcastreceiver and using TelephonyManger API or extending > PhoneStateListener class and registering this new listener > through TelephonyManager . Correct. > In case 2, when the phone state changed, a new testphonestatelistener will > be registered (telephony.listen(phoneListener, > PhoneStateListener.LISTEN_CALL_STATE)), but I could solve this problem > convertingthe TestPhoneStateListener into a Singleton Please don't. > and > using PhoneStateListener listener = TestPhoneStateListener().getInstance() > instead TestPhoneStateListener listener = new TestPhoneStateListener(). > > So my main question is when I have to use each one and for what purposes. Use the listener when you need to find out about the event only when your code is running (e.g., disable some menu choice in an activity). Use the broadcast Intent when you need to find out about the event when none of your code is running. -- Mark Murphy (a Commons Guy) http://commonsware.com | http://github.com/commonsguy http://commonsware.com/blog | http://twitter.com/commonsguy Android Training in London: http://skillsmatter.com/go/os-mobile-server -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

