Hi,
I would really appreciate any ideas regarding the following. Not
disabling the GPS would sap all the battery.
The GPS beacon icon does not go away even though I invoke
LocationManager.removeUpdates in onDestroy. This consistently
reproduces in the emulator.
I have verified in the debugger that the following is happening
correctly:
- onCreate: call LocationManager.requestLocationUpdates
- onDestroy: call LocationManager.removeUpdates
I have tried different values for update interval and distance. I have
also included a small testcase showing the issue at the end of this
post.
Thanks,
--Mano
public class TestActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.test);
startGps();
}
public void onDestroy() {
stopGps();
super.onDestroy();
}
private static long UPDATE_INTERVAL = 1000; //1000ms or 1s
private static float MIN_DISTANCE_FOR_UPDATE = 1; //must move by
1m for update.
LocationManager _locationManager = null;
void startGps() {
try {
_locationManager = (LocationManager)
getSystemService(Context.LOCATION_SERVICE);
//_locationManager.removeUpdates(_locationListener);
_locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,
UPDATE_INTERVAL,
MIN_DISTANCE_FOR_UPDATE,
_locationListener );
}
catch(Exception ign) {
}
}
void stopGps() {
if(_locationManager != null) {
_locationManager.removeUpdates(_locationListener);
}
_locationManager = null;
}
private LocationListener _locationListener = new
LocationListener() {
public void onLocationChanged(Location location) {
if(location!= null) {
Toast.makeText(TestActivity.this, "Location
changed", Toast.LENGTH_SHORT).show();
}
}
public void onProviderDisabled(String provider) {
}
public void onProviderEnabled(String provider) {
}
public void onStatusChanged(String provider, int status,
Bundle extras) {
if(status == LocationProvider.AVAILABLE) {
Toast.makeText(TestActivity.this,
"LocationProvider.AVAILABLE", Toast.LENGTH_SHORT).show();
}
else if(status ==
LocationProvider.TEMPORARILY_UNAVAILABLE) {
Toast.makeText(TestActivity.this,
"LocationProvider.TEMPORARILY_UNAVAILABLE",
Toast.LENGTH_SHORT).show();
}
else if(status == LocationProvider.OUT_OF_SERVICE) {
Toast.makeText(TestActivity.this,
"LocationProvider.OUT_OF_SERVICE", Toast.LENGTH_SHORT).show();
}
}
};
};
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en