android - BroadCast Receiver 太多实例 OutgoingCallBroadcaster;实例=2;限制=1

标签 android broadcastreceiver android-service phone-state-listener

我正在构建一个应用程序,每次调用电话时都会启动一项服务,第一次创建调用时,广播接收器会启动服务,一切都很好。

但接下来的问题是:一旦我再次运行拨号程序,我就会在 LogCat 中收到以下错误:

10-30 10:10:38.674: E/StrictMode(171): class com.android.phone.OutgoingCallBroadcaster; instances=2; limit=1

我已尝试通过在 onReceive 结束时调用此命令来解决问题:

this.abortBroadcast();

这消除了错误,但也停止了服务再次运行,谁能帮我解决这个问题,或者有没有人经历过这种不便?

这是接收器:

   public class OutgoingCallReceiver extends BroadcastReceiver {
    public OutgoingCallReceiver() {
    }

    @Override
    public void onReceive(Context context, Intent intent) {


        // Extract phone number reformatted by previous receivers
        String phoneNumber = getResultData();
        if (phoneNumber == null) {
            // No reformatted number, use the original
            phoneNumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
        }
        Intent in = new Intent(context, OutgoingCallHandler.class);

        context.startService(in);
        OutgoingCallHandler.phonenumber = phoneNumber;


    }
}

这是 list 中的声明:

<service
    android:name=".IncomingCallHandler"
    android:label="@string/title_activity_main" >
</service>

<receiver android:name=".OutgoingCallReceiver" >
        <intent-filter>
            <action android:name="android.intent.action.NEW_OUTGOING_CALL" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </receiver>

非常欢迎大家的帮助!

最佳答案

关于android - BroadCast Receiver 太多实例 OutgoingCallBroadcaster;实例=2;限制=1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26650437/

相关文章:

Android setTextViewText 不起作用

android - 如何在由 AlarmManager 计划启动的服务中检索 Intent Extras?

android - 前台服务卡住用户界面

Android Activity 和 Service 通信 : how to keep the UI up-to-date

android-sdk\docs\reference 丢失

android - 测试是否在仪器测试中调用 finish()

android - 如何在 BroadcastReceiver 中添加 Snackbars?

java - 在 JNI 中正确使用 DeleteLocalRef

java - 无法在 android 模拟器中安装 apk。应用程序包含 ARM 原生代码

android - NFC 广播接收器问题