Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android BluetoothGatt super methods?

When extending BluetoothGattCallback should implementors invoke super methods?

Example:

public void onCharacteristicWrite(BluetoothGatt gatt,
                                  BluetoothGattCharacteristic characteristic, 
                                  int status) {
     // Is this needed?
     super.onCharacteristicWrite(gatt, characteristic, status);

     ...
}
like image 661
Alix Avatar asked Feb 17 '26 06:02

Alix


1 Answers

In this case it seems unnecessary to call super methods. BluetoothGattCallback class is abstract and all its methods are empty.

Edit:

BluetoothGattCallback is part of Android SDK and above the native layer. It's methods are called from BluetoothGatt class which handles callbacks from the native layer and converts them into calls to BluetoothGattCallback methods.

If you wonder why BluetoothGattCallback is an abstract class with empty implementations and not an interface. It's probably because it has too many callback methods, so implementing an interface would cause an unnecessary bloat in the code.

Edit2:

Official reference for this is little difficult to get. Compatiblity definition for hardware manufactures declares that they must implement Android APIs in the form declared in Android SDK.

Note that the underlaying native layer is connected via Android's Binder mechanism.

like image 146
Tomik Avatar answered Feb 18 '26 21:02

Tomik



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!