0

I'm developing an APP that connect to a BLEDevice. This connection is managed by a Sticky Service that have a instance of a singleton that keep all the parameters of the BLE connection (BluetoothDevice,BluetoothGatt,BluetoothGattCallBack).

The behaviour of the APP is resumed in the next lines:

  1. When i open the APP, i click on button that scan, bond and connect to the desire BLE Device.
  2. Once it is connected, appear a Test button that allow me to test if the connection have been stablished correctly by reading a Gatt Characteristic of the BLE Device.
  3. If i kill the app, the service still running due to be Sticky. The point is to not lose the conection with the BLE Device
  4. Then, if i open the app again and i press the test button, it should work.

The problem comes in the point 4. When i click on the test button after close the app one time, i get the next error:

Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.bluetooth.BluetoothGattCharacteristic android.bluetooth.BluetoothGattService.getCharacteristic(java.util.UUID)' on a null object reference

According to my understanding, the problem is that the BluetoothGatt object is lost.

How should i proceed to not lose the BLE connection?

SamuelPS
  • 555
  • 6
  • 20

0 Answers0