The question I was asking might be a bit more concrete that purely theoretical.
As we said the bluetooth device is opened and the corresponding midi device held somewhere (e.g. in the MidiBtlePairing app).
Now, my apps can open the BTLE Midi Device like any other USB midi device.
Imagine I rotate the screen: in most cases onDestroy() and onCreate() are called.
OnDestroy() will clean up the resources including all the MidiDevices held (e.g. MidiInputPortSelector.onClose(), called by MidiScope.MainActivity.onDestroy()).
So by the time onCreate() is called, the BTLE device should have gone.
This is not what I see as the Bluetooth device seems to survive a rotation, while other times it disappears from the drop down a few seconds later.
Does MidiDevice.close() really closes the Bluetooth Device?
If so, then a robust app needs a much more sophisticated handling of device opening that the simple examples provided, probably handing the device management to a ViewModel.
If not, why? What is the exact rule around the lifetime of these devices?
I know I have been asking this for a while, but I can seem to land on a predictable behaviour.
Thank you