Hello again :laughing: One question: the `scope`....
# juul-libraries
f
Hello again 😆 One question: the
scope
.peripheral should be canceled after receiving a disconnect state?
👋 1
t
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
Nice explanation, thank you very much.
👍 1