Bluetooth indoor position use too much memory

220 views Asked by At

I'm trying to do indoor position system with ble devices(beacons) in android. It finds the nearest beacon at the beginning of the program. It detect change becaons position in few seconds but after few seconds it reacts changes too late.

Now i only print id of beacon(i gave this ids)

I think problem is about memory. What could be the problem?

LeScanCallback and Handler function:

@Override
    public void onLeScan(BluetoothDevice device, int rssi, byte[] scanRecord) {
        List<AdRecord> records = AdRecord.parseScanRecord(scanRecord);
        beaconScan = new BluetoothBeacon(records, device.getAddress(), rssi);
        mHandler.sendMessage(Message.obtain(null, 0, beaconScan));

    }

    private Handler mHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {

            beaconHandler = (BluetoothBeacon) msg.obj;
            mBeacons.put(beaconHandler.getAddress(), beaconHandler);

            rssiVal =  getRssiString(beaconHandler);
            dbHelper.insertDevice(beaconHandler.getName(), beaconHandler.getAddress(),
                    rangeValue,rssiVal,currentTime);
            rssiID = model.findNear(beaconHandler.getAddress(),beaconHandler.getSignal());
            Log.i("id", "Nearest beacon id: " + rssiID);

        }
    };
1

There are 1 answers

0
solosodium On

onLeScan is an asynchronous callback, which only will be called when BluetoothAdapter finished scanning. Without the code which initiates the startLeScan, and assuming you did this properly (meaning that you didn't call this function million times a second), there should not be memory issues for this snippet. The few seconds delay is just how scanning works, and it will take some time for the scanning subroutine to run from start to finish.