我有一个 Radio 应用程序,它使用媒体播放器服务和 BroadcastReceiver 来检查传入和传出呼叫以停止或重新启动媒体播放器服务,它可以工作,但是当我退出我的应用程序时,BroadcastReceiver 仍在检查呼叫,它使我的崩溃应用程序即使消失了(已经完成)这里是代码
显现
<service android:name=".PlayerService"
android:label="@string/app_name">
<intent-filter>
</intent-filter>
</service>
<receiver android:name=".IncomingCallInterceptor">
<intent-filter>
<action android:name="android.intent.action.PHONE_STATE"/>
<action android:name="android.intent.action.NEW_OUTGOING_CALL" />
</intent-filter>
</receiver>
广播接收器
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.telephony.TelephonyManager;
public class IncomingCallInterceptor extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
if (PlayerService.getInstance() != null) {
if (TelephonyManager.EXTRA_STATE_RINGING.equals(state)) {
PlayerService.getInstance().stopMusic();
}
if (TelephonyManager.EXTRA_STATE_OFFHOOK.equals(state)) {
PlayerService.getInstance().stopMusic();
}
if (TelephonyManager.EXTRA_STATE_IDLE.equals(state)) {
PlayerService.getInstance().startMusic();
}
}else{}
}
}
我怎样才能让它停止?