Android 位置管理器不会删除位置更新!

Android 位置管理器不会删除位置更新!,android,geolocation,android-intent,locationmanager,android-pendingintent,Android,Geolocation,Android Intent,Locationmanager,Android Pendingintent,可能重复: 我正在尝试禁用我以前在其他活动中创建的挂起意图(广播),但无法使其工作。我已经读到,我应该重新创建意图(使用相同的额外内容和所有内容),将其作为参数传递,以便实例化PendingEvent,然后将PendingEvent作为参数传递给location Manager removeUpdates方法 换言之: 这不起作用,所以我认为这可能与我作为一个新对象传入的意图有关,而与创建挂起的意图所使用的对象不同 因此,我尝试在创建悬挂式帐篷后立即将其移除,但也不起作用: Bundle

可能重复:

我正在尝试禁用我以前在其他活动中创建的挂起意图(广播),但无法使其工作。我已经读到,我应该重新创建意图(使用相同的额外内容和所有内容),将其作为参数传递,以便实例化PendingEvent,然后将PendingEvent作为参数传递给location Manager removeUpdates方法

换言之:



这不起作用,所以我认为这可能与我作为一个新对象传入的意图有关,而与创建挂起的意图所使用的对象不同

因此,我尝试在创建悬挂式帐篷后立即将其移除,但也不起作用:

Bundle extras = new Bundle();

    extras.putString("name", poiName);

    extras.putInt("id", requestCode);

    Intent intent = new Intent(PROX_ALERT_INTENT);

    intent.putExtra(PROX_ALERT_INTENT, extras);

    PendingIntent proximityIntent = PendingIntent.getBroadcast(this.getApplicationContext(), requestCode , intent, PendingIntent.FLAG_CANCEL_CURRENT);

    locationManager.addProximityAlert(
        latitude, // the latitude of the central point of the alert region
        longitude, // the longitude of the central point of the alert region
        POINT_RADIUS, // the radius of the central point of the alert region, in meters
        PROX_ALERT_EXPIRATION, // time for this proximity alert, in milliseconds, or -1 to indicate no expiration 
        proximityIntent // will be used to generate an Intent to fire when entry to or exit from the alert region is detected
   );
    locationManager.removeUpdates(proximityIntent);

你能帮我吗???从星期三开始就一直在窃听…希望我能有更多的名声在这件事上放一个界限

谢谢


mike

通过重新创建意图,然后对挂起的意图调用.cancel()。

mike,如果您创建了一个PendingEvent,然后对其请求LocationUpdate(),则必须移除该PendingEvent对象上的更新()。不能使用新的PendingEvent()或Intent。。您必须以某种方式将原始PendingEvent添加到第二个活动中。@DJC我通过重新创建并取消挂起的意图来实现此目的……显然,如果它不是实际对象,则无所谓,只要您以完全相同的额外内容传入一个意图,并且您可以获得以前使用过的挂起的意图创建…有点奇怪,但它能工作…无论如何感谢你的回复…@DJC好吧,现在我想起来了…你基本上是在覆盖以前的PendingEvent对象,所以它不再存在,新的对象取而代之…所以你有一个实际的参考,以未决的意图,然后你可以取消它:)有一个非常明确的答案公共软件:
Bundle extras = new Bundle();

    extras.putString("name", poiName);

    extras.putInt("id", requestCode);

    Intent intent = new Intent(PROX_ALERT_INTENT);

    intent.putExtra(PROX_ALERT_INTENT, extras);

    PendingIntent proximityIntent = PendingIntent.getBroadcast(this.getApplicationContext(), requestCode , intent, PendingIntent.FLAG_CANCEL_CURRENT);

    locationManager.addProximityAlert(
        latitude, // the latitude of the central point of the alert region
        longitude, // the longitude of the central point of the alert region
        POINT_RADIUS, // the radius of the central point of the alert region, in meters
        PROX_ALERT_EXPIRATION, // time for this proximity alert, in milliseconds, or -1 to indicate no expiration 
        proximityIntent // will be used to generate an Intent to fire when entry to or exit from the alert region is detected
   );
    locationManager.removeUpdates(proximityIntent);