1

I have an android app with min SDK 19, look at in my scenario:

  1. click on button;
  2. BLE scan callback scans around BLE devices and if it find specific device (i have special MAC address, sends to me; 3.returned object has ScannedBleDevice type, i get it and run mGattCallback.connect(...);
  3. i connect to device perfectly and onConnectionStateChanged equals to SUCCESS;
  4. i write a characteristic then read another one;
  5. i update Room data base table depend on recieved data from ble device;
  6. imageviews and textviews on active view Update simultaneously because i use livedata type on room data tables;
  7. exactly after update view, i disconnect from BLE Device without receive any onConnectionStateChange callbacks.

why? i don't know. please help me... i found somethings in these links but not exactly what i want:

Android: Catching BLE Connection Fails/Disconnects?

Android - BLE connection parameter and Storing BLE sensor data in SQLite Database

Android ble device is not disconnecting sometime

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
mortezahosseini
  • 167
  • 1
  • 13

1 Answers1

1

Finally i found the solution: I use MVVM architecture. When my activity created, i read data from database in type and set an Observer on it. then set data to adapter of viewpager and for each data row, add a fragment to viewpager; so in one of my fragment i try to connect to ble device and connection set good. immediately read data from ble device and save in database so observer of data will be called and viewpager set new fragment to view and all last objects in all fragments gone forever, so Callback to ble class vanished and i lose my connection. i set a flag to true at first read and after change data i do not read.

mortezahosseini
  • 167
  • 1
  • 13