diff --git a/Source/Platform Stacks/Robotics.Mobile.Core.Droid/Bluetooth/LE/Device.cs b/Source/Platform Stacks/Robotics.Mobile.Core.Droid/Bluetooth/LE/Device.cs index 0e8cb5a..bb74899 100644 --- a/Source/Platform Stacks/Robotics.Mobile.Core.Droid/Bluetooth/LE/Device.cs +++ b/Source/Platform Stacks/Robotics.Mobile.Core.Droid/Bluetooth/LE/Device.cs @@ -33,17 +33,20 @@ public Device (BluetoothDevice nativeDevice, BluetoothGatt gatt, // when the services are discovered on the gatt callback, cache them here if (this._gattCallback != null) { - this._gattCallback.ServicesDiscovered += (s, e) => { - var services = this._gatt.Services; - this._services = new List (); - foreach (var item in services) { - this._services.Add (new Service (item, this._gatt, this._gattCallback)); - } - this.ServicesDiscovered (this, e); - }; + this._gattCallback.ServicesDiscovered += this.OnServiceDiscovered; } } + public void OnServiceDiscovered(object sender, ServicesDiscoveredEventArgs args) + { + var services = this._gatt.Services; + this._services = new List (); + foreach (var item in services) { + this._services.Add (new Service (item, this._gatt, this._gattCallback)); + } + this.ServicesDiscovered (this, args); + } + public override Guid ID { get { //TODO: verify - fix from Evolve player @@ -104,7 +107,11 @@ public override void DiscoverServices () public void Disconnect () { this._gatt.Disconnect (); - this._gatt.Dispose (); + if (this._gattCallback != null) { + this._gattCallback.ServicesDiscovered -= this.OnServiceDiscovered; + } + this._gatt.Close (); + this._gatt = null; } #endregion