2011-04-19 11 views
0

は私が 無限放送場所の変更

if (locationManager != null && pendingIntent != null) { 
    locationManager.removeUpdates(pendingIntent); 
} 
Intent intent = new Intent("com.app.android.tracker.LOCATION_READY"); 
pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 
      0, intent, PendingIntent.FLAG_UPDATE_CURRENT); 

//Register for broadcast intents 
locationManager.requestLocationUpdates(provider,120000,0,pendingIntent); } 

や放送中

は私が

public class LocationReceiver extends BroadcastReceiver { 
    @Override 
    public void onReceive(Context context, Intent intent) { 

     Logger.debug("LocationReceiver->onRceive"); 
     Bundle b = intent.getExtras(); 
     Location loc = (Location)b.get(android.location.LocationManager.KEY_LOCATION_CHANGED); 
     Logger.debug("Loc:"+loc); 
     if(loc != null){ 
      // 
     } 
    } } 

を行う必要がありreceiveアクティビティで関数を作る持っており、マニフェストに私が今

<receiver android:name=".LocationReceiver"> 
      <intent-filter> 
       <action android:name="com.app.android.tracker.LOCATION_READY" /> 
       <category android:name="android.intent.category.DEFAULT" /> 
      </intent-filter> 
</receiver> 

を持っていながら、私の問題は、任意の場所が更新されている間です。無限に放送されます。エミュレータがハングします。 としばらくの間、ヌル位置が返されます

答えて

1

ロケーションアップデートのリクエストを停止する必要があります。 あなたのonReceiveメソッドでこれを行うことができます:

LocationManager locationManager = (LocationManager) mContext.getSystemService(Context.LOCATION_SERVICE); 
locationManager.removeUpdates(this); 
関連する問題