2

可能重复:
Android: how to cancel a request of Location update with intent?位置经理不删除位置更新!

我试图禁用我已经在不同的活动之前创建一个悬而未决的意图(广播),但我无法得到它的工作。我读过我应该重新创建intent(使用相同的extras和所有内容),将它作为参数传递,以便我可以实例化pendingIntent,然后将pendingIntent作为参数传递给位置管理器removeUpdates方法。

换句话说:


Bundle extra = new Bundle(); 

extra.putString("name", extras.getString("poiName")); //create same extras 

extra.putInt("id", extras.getInt("rowId")); //create same extras 

Intent intent = new Intent(PROX_ALERT_INTENT); 

intent.putExtra(PROX_ALERT_INTENT, extra); //put same extras in the intent 

PendingIntent proximityIntent = PendingIntent.getBroadcast(this.getApplicationContext(),extras.getInt("rowId") , intent, PendingIntent.FLAG_UPDATE_CURRENT); //pass in the intent 

LocationManager locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE); 
               locationManager.removeUpdates(proximityIntent); //remove pendingIntent 

那没有工作,所以我认为这可能与,即时通讯传递是一个新的对象的意图和不一样的做与用于创建待定意图的那个一起使用。

所以我试图消除的PendingIntent创建之后,但没有工作之一:

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); 

能否请你帮我带在于:它被窃听是因为周三...希望我有更多的信誉把boundy在这一个...

感谢

迈克

+0

迈克,如果你创建一个PendingIntent,然后requestLocationUpdates()就可以了,你必须removeUpdates()在* same * PendingIntent对象上。您不能使用* new * PendingIntent()或Intent ..您必须以某种方式将原始PendingIntent获取到第二个活动。 – DJC 2011-02-11 09:24:15

回答

4

通过重新创建的意图,然后调用.cancel(解决它)在待定的意图...