Android Ble Bluetooth開発メモリ漏れ
482 ワード
Android Ble Bluetoothの開発でメモリが漏れやすい場所を2つ記録します. BluetoothスキャンBluetooth Adapterとして使用する.LeScanCallbackは内部クラスとしてstaticとして定義し、コールバック内部でactivityの参照が必要な場合は弱い参照で包む.参考:It leaks when I startLeScan in onCreate and stopLeScan in onDestroy Bluetooth接続ble Bluetooth接続の場合、パラメータとしてcontextを入力する必要があります.
BluetoothGatt connectGatt(Context context, boolean autoConnect, BluetoothGattCallback callback)
、このcontextはgetApplicationContext()
で取得され、メモリの漏洩を効果的に回避できます.