简体   繁体   中英

Proximity alert not removing

I added some alert to locationManager. I have problem in removing that alert. When I remove alert, it keeps working and is not removed. Here is the code:

public class DisplayLocation extends SupportMapFragment implements OnCameraChangeListener,
    LocationListener {

    LocationManager locationManager;
    @Override
    public View onCreateView(LayoutInflater arg0, ViewGroup arg1, Bundle arg2) {
        View v = super.onCreateView(arg0, arg1, arg2);
        locationManager = (LocationManager) getActivity().getSystemService(
                                                         getActivity().LOCATION_SERVICE);
        String []token = address.split(",");
        LatLng Position = new LatLng(Double.parseDouble(token[0]),
                                     Double.parseDouble(token[1]));
        Intent proximityIntent = new Intent("com.example.proximity");
        proximityIntent.putExtra("name",name);
        pendingIntent = PendingIntent.getActivity(getActivity().getBaseContext(), 5,
                                          proximityIntent,Intent.FLAG_ACTIVITY_NEW_TASK);
        locationManager.addProximityAlert(Position.latitude, Position.longitude, 
                                            Integer.parseInt(radius), -1, pendingIntent);
}

and then I have coded this in button for removing that proximity alert in another class extended from arrayadapter

LocationManager locationManager = (LocationManager)mContext.getSystemService(
                                                               Context.LOCATION_SERVICE);
Intent intent = new Intent(".Proximity");
PendingIntent pintent = PendingIntent.getActivity(mContext, 5, intent, 0);
locationManager.removeProximityAlert(pintent);

But this doesn't work.

The call to LocationManager.removeProximityAlert() must be passed the same Intent as was used to add the alert. You are constructing a new Intent and while it may be identical in content to the original, it is not the same object.

So, when setting the alert, save the Intent in a field, and use it when you want to remove the alert rather than creating a new one.

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