简体   繁体   English

从BroadcastReceiver取消注册PhoneStateListener

[英]Unregister PhoneStateListener from BroadcastReceiver

I am monitoring phone state through broadcast receiver, and for that I register a PhoneStateListener in onReceive of the receiver. 我正在通过广播接收器监视电话状态,为此,我在接收器的onReceive中注册了PhoneStateListener。 Now if user wants to disable this feature, I disable the broadcast receiver, but the listener keeps running, and i am notified of the phone state. 现在,如果用户想禁用此功能,我将禁用广播接收器,但是侦听器将继续运行,并且会通知我电话状态。 How can I unregister the PhoneStateListener registered in the broadcast receiver? 如何注销在广播接收器中注册的PhoneStateListener?

As the documentation says: 文档所述

To unregister a listener, pass the listener object and set the events argument to LISTEN_NONE (0). 要取消注册侦听器,请传递该侦听器对象,并将events参数设置为LISTEN_NONE(0)。

For example: 例如:

    telephonyManager.listen(myListener, PhoneStateListener.LISTEN_NONE);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM