Error:android.app.ServiceConnectionLeaked:就是leaked ServiceConnection的错误

本文介绍了解决Android开发中ServiceConnection泄漏的问题。通过确保在Activity销毁时解除服务绑定,避免内存泄漏的发生。

  在做activity和service绑定时候,出现了这个错误。

android.app.ServiceConnectionLeaked: Activity com.dxn.xtgascehui.activity.MappingActivity has leaked XServiceConnection  com.dxn.xtgascehui.activity.MappingActivity$2 @926151f that was originally bound here

最后发现是只做了绑定,未做解绑。

解决办法:在onDestory()方法中解绑就可以了

//解绑服务
if (mService == null) {
    return;
}
try {
    mService.removeUpdates(listener);
} catch (RemoteException e) {
    e.printStackTrace();
}
unbindService(mConnection);

01-01 00:02:21.587057 7964 7964 D BluetoothAdapterService: Loading JNI Library 01-01 00:02:21.686857 7964 7964 D BluetoothAdapterService: Load JNI library first. 01-01 00:02:21.686966 7964 7964 D BluetoothAdapterService: Load JNI library done. 01-01 00:02:21.687063 7964 7964 D BluetoothAdapterService: onCreate() 01-01 00:02:21.687170 7964 7964 D BluetoothAdapterService: init() 01-01 00:02:23.699015 7964 7964 I BluetoothAdapterService: Phone policy enabled 01-01 00:02:25.377335 7964 7964 I OplusBluetoothRecorderFactory: init() 01-01 00:02:25.500317 7964 8525 D OplusBluetoothRecorderFactory: handle message, msg = 1 01-01 00:02:25.500525 7964 8525 D OplusBluetoothRecorderFactory: processLoadRecordedDevices begin++ 01-01 00:02:25.500796 7964 8525 W OplusBluetoothRecorderFactory: Load recorded device from /data/user_de/0/com.android.bluetooth/files/recorded_dev_info.conf 01-01 00:02:25.501349 7964 8525 D OplusBluetoothRecorderFactory: processLoadRecordedDevices end++ 01-01 00:02:25.581329 7964 7964 D BluetoothAdapterService: setAdapterService() - set service to com.android.bluetooth.btservice.AdapterService@da13eaa 01-01 00:02:25.606743 7964 7964 D BluetoothAdapterService: updateAdapterState() - Broadcasting state OFF to 0 receivers. 01-01 00:02:25.607569 7964 7964 D BluetoothAdapterService: onBind() 01-01 00:02:25.651373 7964 7964 D BluetoothAdapterService: onUnbind() 01-01 00:02:25.651939 7964 7964 D BluetoothAdapterService: onDestroy() 01-01 00:02:25.764463 7964 7964 E ActivityThread: Service com.android.bluetooth.btservice.AdapterService has leaked IntentReceiver com.oplus.bluetooth.feature.dcs.OplusBluetoothRecorderFactory$1@a992db3 that was originally registered here. Are you missing a call to unregisterReceiver()? android.app.IntentReceiverLeaked: Service com.android.bluetooth.btservice.AdapterService has leaked IntentReceiver com.oplus.bluetooth.feature.dcs.OplusBluetoothRecorderFactory$1@a992db3 that was originally registered here. Are you missing a call to unregisterReceiver()? at com.oplus.bluetooth.feature.dcs.OplusBluetoothRecorderFactory.init(OplusBluetoothRecorderFactory.java:305) 01-01 00:02:25.796221 7964 7964 D BluetoothAdapterService: Load JNI library first. 01-01 00:02:25.796328 7964 7964 D BluetoothAdapterService: Load JNI library done. 01-01 00:02:25.796386 7964 7964 D BluetoothAdapterService: onCreate() 01-01 00:02:25.796422 7964 7964 D BluetoothAdapterService: init() 01-01 00:02:26.252769 7964 7964 I BluetoothAdapterService: Phone policy enabled 01-01 00:02:26.444844 7964 7964 D BluetoothAdapterService: setAdapterService() - set service to com.android.bluetooth.btservice.AdapterService@a41c432 01-01 00:02:26.482332 7964 7964 D BluetoothAdapterService: updateAdapterState() - Broadcasting state OFF to 0 receivers. 01-01 00:02:26.482648 7964 7964 D BluetoothAdapterService: onBind() 在这段·日中 BluetoothAdapterService 初始化了两次
09-29
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值