Android:アクティビティが終了した後にPhoneCallListenerがまだ生きているのはなぜですか?

StackOverflow https://stackoverflow.com//questions/11666853

質問

私の活動で電話をかけたリスナーを使っていますが、私の活動を終えた後は、ユーザーが電話をかけて、私の電話の呼び出し側は死んでいて再びブリッグされました!私を助けてください。

phoneListener = new PhoneCallListener();
telephonyManager = (TelephonyManager) 
            TransferActivity.this.getSystemService(Context.TELEPHONY_SERVICE);
telephonyManager.listen(phoneListener,  PhoneStateListener.LISTEN_CALL_STATE);
.

PhoneCallListenerクラス:

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);
                }
            }
        }
    }
}
.

役に立ちましたか?

解決

文書は言う:

リスナーを登録するには、リスナーオブジェクトを渡してイベントを設定します PhonestateListener#listen_none(0)

これは docs

他のヒント

リスナーをNULLに設定して、

telephonyManager.listen(null,  PhoneStateListener.LISTEN_NONE);
.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top