安卓:为什么PhoneCallListener还活着,活动结束后? [英] Android : why PhoneCallListener still alive after activity finish?
本文介绍了安卓:为什么PhoneCallListener还活着,活动结束后?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的活动,但我完成活动后使用电话监听器的IM,AFER用户拨打一个电话,我的电话监听器没有死,再次布里格后续活动!请帮助我。
phoneListener =新PhoneCallListener();
telephonyManager =(TelephonyManager)
TransferActivity.this.getSystemService(Context.TELEPHONY_SERVICE);
telephonyManager.listen(phoneListener,PhoneStateListener.LISTEN_CALL_STATE);
PhoneCallListener类:
私有类PhoneCallListener扩展PhoneStateListener {
布尔isPhoneCalling = FALSE;
@覆盖
公共无效onCallStateChanged(INT状态,串incomingNumber){
如果(TelephonyManager.CALL_STATE_RINGING ==州){
}
如果(TelephonyManager.CALL_STATE_OFFHOOK ==州){
isPhoneCalling = TRUE;
}
如果(TelephonyManager.CALL_STATE_IDLE ==州){
如果(isPhoneCalling){
isPhoneCalling = FALSE;
意向意图= getIntent();
startActivity(意向);
}
}
}
}
}
解决方案
该文件说:
要注销侦听,通过侦听器对象,并设置事件参数LISTEN_NONE(0)。
下面是链接到<一个href="http://developer.android.com/reference/android/telephony/TelephonyManager.html#listen%28android.telephony.PhoneStateListener,%20int%29"相对=nofollow>文档
im using a phone call listener in my activity but after finishing my activity , afer user make a call, my phone call listener not dead and brig up activity again !! please help me.
phoneListener = new PhoneCallListener();
telephonyManager = (TelephonyManager)
TransferActivity.this.getSystemService(Context.TELEPHONY_SERVICE);
telephonyManager.listen(phoneListener, PhoneStateListener.LISTEN_CALL_STATE);
PhoneCallListener class :
private class PhoneCallListener extends PhoneStateListener {
boolean isPhoneCalling = false;
@Override
public void onCallStateChanged(int state, String incomingNumber) {
if (TelephonyManager.CALL_STATE_RINGING == state) {
}
if (TelephonyManager.CALL_STATE_OFFHOOK == state) {
isPhoneCalling = true;
}
if (TelephonyManager.CALL_STATE_IDLE == state) {
if (isPhoneCalling) {
isPhoneCalling = false;
Intent intent = getIntent();
startActivity(intent);
}
}
}
}
}
解决方案
The documentation says:
To unregister a listener, pass the listener object and set the events argument to LISTEN_NONE (0).
Here is the link to the Doc
这篇关于安卓:为什么PhoneCallListener还活着,活动结束后?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文