https://kotlinlang.org logo
#juul-libraries
Title
# juul-libraries
f

Francis Mariano

07/15/2021, 5:17 PM
Hello again 😆 One question: the
scope
.peripheral should be canceled after receiving a disconnect state?
👋 1
t

travis

07/16/2021, 2:33 AM
It is up to you when to cancel the
scope.
You should cancel it when you no longer need the
scope
and any of the peripherals created from it.
If after disconnected, you no longer need the peripheral, then cancelling the
scope
makes sense. Although if you plan to later reconnect, then you can leave the
scope
active.
In disconnected state, peripherals are fairly lightweight. I have not profiled them, but I suspect they are very low memory overhead. On Android they hold a reference to a
BluetoothDevice
(which according to Android docs is just a thin representation of a MAC address). Aside from that, peripheral just listens to a broadcast receiver to monitor Bluetooth state. So basically, fine to have a bunch of active peripherals sitting around.
On the flip side, re-creating a peripheral isn't expensive either. So cancelling the
scope
and later using a new
scope
and creating new peripherals is also fine.
f

Francis Mariano

07/16/2021, 6:13 PM
Nice explanation, thank you very much.
👍 1
3 Views