When I detect that data isn't coming in (therefore my bluetooth device is switched off) I shut down the bluetooth like this:
AStream.Close
serial1.Disconnect
admin.Disable
Then, my Admin_statechanged function looks like below, it just switched the blueooth back on the moment it gets turned off and gets it listening again:
Sub Admin_StateChanged (NewState As Int, OldState As Int)
If NewState = admin.STATE_ON Then
serial1.Listen
'ToastMessageShow("listening",False)
Else
UNIT_CONNECTED = False
If admin.IsEnabled = False Then
admin.Initialize("admin")
If admin.Enable = False Then
ToastMessageShow("Error enabling Bluetooth adapter.", True)
End If
End If
End If
End Sub
and job done