The situation is that I have my listener constructed using an anonymous inner class, as is typical, but the way of deregistering a [PhoneStateListener][1] in Android requires me to pass the listener object to the this same function that I used to register it, but use the LISTEN_NONE flag. The problem is that I can't do this with an anonymous inner class because it's, well, anonymous. Do I have to instantiate my class with a name to be able to de-register it, or can I just ignore this problem and my listener will disappear by itself when my service terminates?
views:
30answers:
1
+1
A:
You can assign your anonymous class to a variable, and thus pass it in multiple places:
PhoneStateListener listener = new PhoneStateListener() {
// class definition;
}
Mayra
2010-09-16 01:42:44
Perfect! I'm a bit new to anonymous classes so I didn't realise this was possible. Cheers.
Sam Svenbjorgchristiensensen
2010-09-16 02:04:16