Currently I display user's location at MapView:
MyLocationOverlay myLocationOverlay = new MyLocationOverlay(this, mapView);
mapView.getOverlays().add(myLocationOverlay);
myLocationOverlay.enableMyLocation();
But once user closes MapView
activity (press ba开发者_Python百科ck button) or even closes MainActivity
(presses back again), GPS icon is still displayed in the status bar. Looks like GPS is still used. Should I do something in my code to avoid that?
Yes you need to stop GPS usage to avoid battery draining, following methods will stop GPS usage used in relevant methods like OnPause, onStop, onDestroy:
MyLocationOverlay.disableMyLocation();
LocationManager.removeUpdates(LocationListener);
精彩评论