Android: ¿Por qué PhoneCalllistener sigue vivo después de terminar la actividad?
-
12-12-2019 - |
Pregunta
Estoy usando un escuchador de llamadas telefónicas en mi actividad, pero después de terminar mi actividad, Afer Usuario haga una llamada, ¡mi escucha de llamada telefónica no está muerta y se vuelve a broig.por favor ayúdame
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);
}
}
}
}
}
Solución
La documentación dice:
para no registrar a un oyente, pasar el objeto de oyente y configurar los eventos argumento a fonestatelistener # escuchar_none (0)
Aquí está el enlace al docs .
Otros consejos
¿Intentó configurar al oyente a NULL como,
telephonyManager.listen(null, PhoneStateListener.LISTEN_NONE);
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow