2011-05-08 44 views
0

這是我使用的requestLocationUpdates調用,900000(15分鐘)和500米不應該導致gps不斷髮射,其真正耗盡電池。 ..Android requestLocationUpdates與15分鐘的間隔導致gps指標不斷髮射

我知道這段代碼沒有幫助..但是有沒有人知道爲什麼會發生這種情況?

我onStartCommand

mlocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 900000, 500, locationListener); 
mLocation = mlocManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); 

然後

private final LocationListener locationListener = new LocationListener() { 
    public void onLocationChanged(Location location) { 
     mLocation = location; 
    } 

    @Override 
    public void onProviderDisabled(String arg0) {} 
    @Override 
    public void onProviderEnabled(String arg0) {} 
    @Override 
    public void onStatusChanged(String arg0, int arg1, Bundle arg2) {} 
}; 

回答

0

的時間參數requestLocationUpdates()是一個提示,而不是一個規則 - 你可能會得到位置的頻率高於此。

如果您想要停止使用GPS,請撥打removeUpdates()

+0

好的,謝謝。我只是覺得這很奇怪,因爲在我的服務開始後,gps圖標不會消失。 – David 2011-05-08 22:18:23

+0

@大衛:如果你正在模擬器上測試,GPS圖標永遠不會消失。這是模擬器中一個長期存在的缺陷。在設備上,當您調用'removeUpdates()'時,GPS圖標應該消失,假設沒有其他應用程序保持GPS通電。 – CommonsWare 2011-05-08 22:49:38

相關問題