I'm playing with a GPS application and am having issues when the screen rotates.
The following is what I use to create the location updates and stop them when the screen rotates.
The app, when started shows the speed and location updates, once the screen rotates I no longer have the speed updates, although the location update procedure does kick in as the location changes and I update an elapsed time within it.
Here is the code, have I missed something obvious?
The following is what I use to create the location updates and stop them when the screen rotates.
The app, when started shows the speed and location updates, once the screen rotates I no longer have the speed updates, although the location update procedure does kick in as the location changes and I update an elapsed time within it.
Here is the code, have I missed something obvious?
Code:
@Override
public void onResume() {
super.onResume();
locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
if(gps<2){
try {
// get location manager to check gps availability
boolean isGPS = locationManager.isProviderEnabled (LocationManager.GPS_PROVIDER);
if(!isGPS){
gps++;
if(gps<2) checkGps();
else finish();
}
else{
gps=2;
//gps is available, do actions here
}
} catch (Exception e1) {
gps++;
if(gps<2) checkGps();
else finish();
}
}
if (listenerFine == null){
listenerFine = null;
}
listenerFine = new LocationListener() {
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
@Override
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onLocationChanged(Location location) {
// TODO Auto-generated method stub
speed = location.getSpeed() ;
<[I]Other stuff being updated etc in here[/I]>
}
};
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000L,1.0f, listenerFine);
}
public void onPause() {
super.onPause();
locationManager.removeUpdates(listenerFine);
}