如何销毁PhoneStateListener类的对象?
问题描述:
在某些情况下,我不想听我的手机状态。 如何销毁PhoneStateListener类的对象?如何销毁PhoneStateListener类的对象?
我创建对象这样
try {
phoneCallListener = new WnetPlayerPhoneCallListener();
TelephonyManager mTM = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);
mTM.listen(phoneCallListener, PhoneStateListener.LISTEN_CALL_STATE);
} catch(Exception e) {
Log.e("PhoneCallListener", "Exception: "+e.toString());
}
答
每this answer,你应该保持到TelephonyManager
和WnetPlayerPhoneCallListener
参考,并将其设置为禁用,像这样:
mTm.listen(phoneCallListener, PhoneStateListener.LISTEN_NONE);
为什么他们不这样做只是有标准的addListener()
和removeListener()
方法,我不知道,但这似乎是解决您的问题的公认方法。
非常感谢Dan S – 2012-04-26 10:42:06