I am developing an android application that use google-play-services-lib. This app has a google map and use locationManager to determine user location. Next find google Places and track google directions for them. In my code i use
@Override
protected void onDestroy(){
super.onDestroy();
}
But the com.google.android.gms services dont stop (even if wifi, 3G and gps turn off) and the battery drain. When i see battery usage of my device it has
CPU total usage 2min 3sec
CPU usage in background 2min 3sec
GPS 10 hours 30min.
In my code the only situations that require location update are
@Override
public void onLocationChanged(Location location) {
mLatitude = location.getLatitude();
mLongitude = location.getLongitude();
LatLng latLng = new LatLng(mLatitude, mLongitude);
mGoogleMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
mGoogleMap.animateCamera(CameraUpdateFactory.zoomTo(12));
}
and
// Getting LocationManager object from System Service LOCATION_SERVICE
LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
// Creating a criteria object to retrieve provider
Criteria criteria = new Criteria();
// Getting the name of the best provider
String provider = locationManager.getBestProvider(criteria, true);
// Getting Current Location From GPS
Location location = locationManager.getLastKnownLocation(provider);
locationManager.requestLocationUpdates(provider, 2000, 0, this);
But i thought that with super.destroy() that functions stop.
Can anyone help me with my problem? Thanks in advance!
you need to remove the updates. It will work in other thread Try this:
@Override
public void onDestroy() {
locationManager.removeUpdates(this);
super.onDestroy();
}