Android 中导入百度地图后,activity已经退出了但是service 还是没有停下

来源:互联网 发布:php jquery ajax登录 编辑:程序博客网 时间:2024/06/02 17:24
在导入了百度地图的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()就可以了,

@Overrideprotected void onDestroy() {    super.onDestroy();    mMapView.onDestroy();    mLocationClient.unRegisterLocationListener(this);    //千万别忘了这个stop,如果不stop那么会继续执行    mLocationClient.stop();}


0 0