What happens to the BluetoothGatt status when a Ble connection is established and services are discovered. After the services are discovered and if activity is changed with different GUI does the BluetoothGatt becomes null?
Asked
Active
Viewed 762 times
0
-
It usually happens when your connection is terminated or BluetoothGatt is not been initialised and you are try to access it !! – Punit Sharma Jan 19 '16 at 11:29
-
I am pretty sure that connection is successful and not being terminated. – Arun Jan 19 '16 at 11:40
-
After the connection is successful I want to start a new activity witch new Gui with buttons and on click of this button i want to send some data to connected ble device. But the problem is I am getting my gatt as null. – Arun Jan 19 '16 at 11:43
-
i think you are binding the service to the activity , so when you go to a new activity service is been killed. – Punit Sharma Jan 19 '16 at 12:02
-
can you please suggest me the way in which i can get rid of this issue. – Arun Jan 19 '16 at 13:30
1 Answers
0
You have to keep a reference to the instance of BluetoothGatt and pass this reference to the new Activity. Or you can run a started service and keep the BluetoothGatt instance in here, so it will survive the destroy of the current activity. Then you can bind to the service in the new activity and call methods upon it.
This seems to be a better option because the handling of the BluetoothGatt actions and callbacks is not dependend on the activity lifecycle. It's all described pretty well in the docs.

JPS
- 604
- 5
- 14