Android: Perché PhoneCallListender è ancora vivo dopo la finitura delle attività?
-
12-12-2019 - |
Domanda
IM Uso di un listener telefonico della telefonata nella mia attività, ma dopo aver terminato la mia attività, Afer Utente effettuare una chiamata, il mio listener della telefonata non è morto e si accumula nuovamente l'attività !!per favore aiutami.
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);
}
}
}
}
}
. Soluzione
La documentazione dice:
.Per registrare un ascoltatore, passare l'oggetto listener e impostare gli eventi Argomento a Phonestatelistener # Ascolta_none (0)
Ecco il link a Documenti .
Altri suggerimenti
Hai provato a impostare l'ascoltatore di NULL AS,
telephonyManager.listen(null, PhoneStateListener.LISTEN_NONE);
. Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow