开发者

Do I need to stop GPS usage once MapView activity is closed?

开发者 https://www.devze.com 2023-03-17 15:07 出处:网络
Currently I display user\'s location at MapView: MyLocationOverlay myLocationOverlay = new MyLocationOverlay(this, mapView);

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);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号