Registering to Same Receiver Multiple times

Viewed 4800

For some reason I need to register to same receiver multiple times like one in the Manifest and one time in the code. I want to listen package changes even the app is not running but installed.

1.In the AndroidManifest.xml

<receiver android:name="PackageChangeReceiver">
    <intent-filter>
        <action android:name="android.intent.action.PACKAGE_CHANGED" />
        <action android:name="android.intent.action.PACKAGE_ADDED" />
        <action android:name="android.intent.action.PACKAGE_REMOVED" />
        <action android:name="android.intent.action.PACKAGE_REPLACED" />
        <data android:scheme="package" />
    </intent-filter>

2.Also in the code I register to BroadcastReceiver with the following code snippet in the constructor of.

public PackageChangeReceiver(@ForApplication Context context) {
    super();
    IntentFilter filter = new IntentFilter(Intent.ACTION_PACKAGE_ADDED);
    filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
    filter.addAction(Intent.ACTION_PACKAGE_CHANGED);
    filter.addDataScheme("package");
    context.registerReceiver(this, filter);
}

But somehow Android only receives one of them intermittently sometime it receives both. Is there any doc in the newer versions like a performance improvement in Android OS itself such as only receiving one broadcast although registered to multiple times. Is it device or OS or version specific thing?

1 Answers
Related