我需要在整個應用程序中實現一個LocationListener。整個應用程序中的一個LocationListener
我知道我可以在LocationListener中使用服務,但問題是我必須在位置發生變化時使用某個通知程序。只要我能夠獲得最後的位置,這是不夠的,因爲我需要在所有活動中立即更新當前位置。
因此,在僞代碼,我需要類似的東西:
myLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, new LocationListener() {
public void onLocationChanged(Location location) {
notifyAllActivities(location);
}
};
,並在每個活動時間:
void onNotify(Location location) { //... }
接受適合您的答案,以便其他人可能會覺得它有用。 – 2012-08-06 00:38:37