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(解決它)在待定的意圖...