简体   繁体   中英

Android Marshmallow broadcastreceiver receiving multiple broadcasts for each send

My application has a subclass broadcast receiver:

   public class LocationBroadcastReceiver extends BroadcastReceiver {
    LocationBroadcastReceiver.class.getSimpleName();
        @Override
        public void onReceive(Context context, Intent intent) {
            if (intent.getAction().equals(Constants.BROADCAST_LOCATION_ACTION)) {
                Bundle extras = intent.getExtras();
                 Log.d(LOG_TAG, "BCAST LAT = " + extras.getDouble("LAT") + " LON = " + extras.getDouble("LON"));
            }
}

Generate a log message in the service that sends the broadcast and the log message above. Getting multiple broadcasts for a single broadcast message sent.

I am dynamically registering the receiver using the following:

mLocateBcast = new LocationBroadcastReceiver();
        IntentFilter locationFilter = new IntentFilter();
        locationFilter.addAction(Constants.BROADCAST_LOCATION_ACTION);

LocalBroadcastManager.getInstance(mContext).registerReceiver(mLocateBcast,locationFilter);

I do not have a receiver defined in my manifest. In previous Android versions I received a single broadcast for a similar setup. What am I missing?

With Marshmallow, the onLocationChanged callback is called when the LocationRequest setInterval value expires regardless of whether there has been an actual location change.

Was not expecting this behavior.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM