Question

I implemented a PhoneStateListener how stops audio if you are called and starts it again after you finished. When i exit my app by finish() the PhoneStateListener seems to be still active. After finishing a call the music starts to play. Even if I set the listener=null in onDestroy() it keeps working...

Was it helpful?

Solution

Quoting the documentation for listen() on TelephonyManager:

To unregister a listener, pass the listener object and set the events argument to LISTEN_NONE (0).

You must do this before your activity goes out of scope, such as in onPause() or onDestroy().

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top