5

I have gone trough several resources which deal with this problem, but none with a satisfactory explanation or solution. Some of the content I have gone through are:

Broadcast receiver called 2 times when turning off GPS?

My BroadcastReceiver is called two times when turning on/off wifi or gps?

android.location.PROVIDERS_CHANGED BroadcastReceiver fires off many times

How to catch GPS off broadcast once?

I therefore, am re-posting this question.

The problem statement is simple, I have a broadcast receiver that gets triggered whenever there is a change in the GPS/Location status of the device. The problem is that the onReceive() method gets called more than once (4 times to be precise).

I have registered my receiver in my manifest file (and nowhere else):

        <receiver android:name=".broadcasts.DeviceGpsStatusReceiver">
            <intent-filter>
                <action android:name="android.location.PROVIDERS_CHANGED" />

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

I have also ensured that this receiver isn't registered anywhere else within my application.

The broadcast receiver is designed as follows:

    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent.getAction().matches("android.location.PROVIDERS_CHANGED")) {
            // my content
        }
    }

Even with this change, I see the onReceive() overridden method being triggered multiple times. Why is this the case? Is there a way to resolve this?

mang4521
  • 742
  • 6
  • 22

0 Answers0