In the Android app I'm developing, I need the LocationManager to give me location fixes. This part is good and good; It works, it has been quite a long time, and everyone there is happy.
However, now that I have also recently added a feature that allows the location tracking part to go to the background, I also want it to slow down updates in this case in order to save battery power. In fact, the way I'm trying to do this is to call requestLocationUpdates again with new parameters if my background service detects that there are no more registered listeners (it provides something in the notification bar, so I still want it to receive updates ) Let me call this service "Servicemajig". The way I do this is shorter:
private void setMode(boolean foreground) {
if(foreground == mForeground) return;
mForeground = foreground;
if(mForeground) {
Log.i(DEBUG_TAG, "Switching to foregroud mode...");
mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, Servicemajig.this);
} else {
Log.i(DEBUG_TAG, "Switching to background mode...");
mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 30000, 0, Servicemajig.this);
}
}
, . (.. , ), Nexus One G1 . , 30 ( ), , .
, Motorola Droid. Droid , , 30 ( , ) , , . , , , , 30 , , Servicemajig . , , , , .
, : , Droid? , ? - ? , , removeUpdates if registerLocationUpdates.