Search code examples
androidbroadcastreceiverandroid-servicephone-state-listener

BroadCast Receiver too many instances OutgoingCallBroadcaster; instances=2; limit=1


I am building an app that starts a service each time a call is being made, the first time I create a call the broadcast receiver starts the service and all is well.

But then the problem: Once I run the dialer again I get the following error in LogCat:

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

I have tried solving the problem by calling this command at the end of the onReceive:

this.abortBroadcast();

This removes the error, but also stops the service from running again, can anyone help me fix this problem, or is there anyone who has experienced this inconvieniance?

This is the receiver:

   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;


    }
}

And here are the declarations in the manifest:

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

All the help is very welcom!


Solution