在导入了百度地图的activity 中,我退出了activity 但是后台的service 还是继续执行,有这样的一条信息
03-13 22:42:11.913 27433-27449/tech.androidstudio.baidulocationdemo I/art: Background sticky concurrent mark sweep GC freed 272437(9MB) AllocSpace objects, 12(972KB) LOS objects, 27% free, 20MB/28MB, paused 5.857ms total 63.015ms
原因分析,这个是因为我取消LocationClient 的注册的时候没有将LocationClient 进行停止。
解决办法:
在onDestroy 的里面加上 mLocationClient.stop()就可以了,
@Override protected void onDestroy() { super.onDestroy(); mMapView.onDestroy(); mLocationClient.unRegisterLocationListener(this); //千万别忘了这个stop,如果不stop那么会继续执行 mLocationClient.stop(); }

本文讨论了在使用百度地图SDK的Android应用中,退出Activity后服务仍在后台执行的问题,并提供了解决方法:在Activity的onDestroy方法中调用LocationClient的stop()方法来停止服务。
1069

被折叠的 条评论
为什么被折叠?



