记录2个Android Ble蓝牙开发容易导致内存泄漏的地方:

  1. 蓝牙扫描
    当BluetoothAdapter.LeScanCallback作为内部类时要定义成static,如果回调内部需要用到activity的引用,要使用弱引用包裹起来。参考:It leaks when I startLeScan in onCreate and stopLeScan in onDestroy

  2. 蓝牙连接
    ble蓝牙连接时,需要传入一个context作为参数,BluetoothGatt connectGatt(Context context, boolean autoConnect, BluetoothGattCallback callback),这个context使用getApplicationContext()获取,可以有效避免内存泄漏。

更多相关文章

  1. Arduino 制作蓝牙开关
  2. Android(安卓)内存溢出(Out Of Memory)的总结
  3. Android(安卓)Studio和MAT结合使用来分析内存问题
  4. zz:Android(安卓)内存溢出(Out Of Memory)的总结
  5. 给android imageView(图片) 添加超链接
  6. android 拨号器
  7. 多线程在Android中应用
  8. android ble蓝牙开发略解
  9. 蓝牙操作 Bluetooth

随机推荐

  1. 【实战】android网页源代码查看器
  2. How to parse / read JSON data into a A
  3. 移动web开发经验总结
  4. Android NDK 配置与打包
  5. Android获取StatusBa有效高度
  6. Android开发遇到的问题----自定义Recycle
  7. Android积木之 点击空白区域隐藏小键盘
  8. Android 出错显示找不到id,但你发现id是存
  9. Android 下载服务器上的文件
  10. Android 调用系统的照相,浏览图片,转存并裁