BroadCast Receiver太多实例OutgoingCallBroadcaster;实例= 2;极限= 1

时间:2014-10-30 10:21:23

标签: 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;


    }
}

以下是清单中的声明:

<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>

所有帮助都非常热情!

1 个答案:

答案 0 :(得分:1)