我运行我的代码并旋转手机几次,然后转储内存并对其进行分析。
下面是我的代码:
private BluetoothAdapter.LeScanCallback mLeScanCallback = new BluetoothAdapter.LeScanCallback() {
@Override
public void onLeScan(BluetoothDevice device, int rssi, byte[] scanRecord) {
LogUtils.e("111");
}
};
private boolean mScanning = false;
private BluetoothManager bm;
private void scanLeDevice(final boolean enable) {
LogUtils.e(enable);
try {
if (enable) {
mScanning = true;
if(bm.getAdapter()!=null)bm.getAdapter().startLeScan(mLeScanCallback);
} else {
mScanning = false;
if(bm.getAdapter()!=null)bm.getAdapter().stopLeScan(mLeScanCallback);
}
invalidateOptionsMenu();
}catch (Throwable e){
}
}
@Override
protected void onDestroy() {
super.onDestroy();
scanLeDevice(false);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
initStage();
}
@Override
protected void initStage() {
bm = (BluetoothManager)getSystemService(Context.BLUETOOTH_SERVICE);
scanLeDevice(true);
}