Turning off bluetooth on exit.

ardhuru

Member
Licensed User
Longtime User
Hi,

In the new serial tutorial by Erel, the bluetooth adapter comes on automatically, if its not on already, when the program is launched.

My question is, can it also be disabled automatically when the program exits (application is closed)?

Regards,

Anand
 

ardhuru

Member
Licensed User
Longtime User
Please forgive my amateurish questions, but do I just insert the string in the bracket in the Activity_Pause sub?

I changed

Sub Activity_Pause (UserClosed As Boolean)
Serial1.Disconnect
End Sub

to

Sub Activity_Pause (UserClosed As Boolean)
UserClosed = True
Serial1.Disconnect
End Sub

This did not help. Both versions disconnect the existing BT connection on exit, but neither switches off the bluetooth adapter in the device.

As you can see, I'm at the very early stages of the learning curve...

Thanks again,

Anand.
 
Upvote 0

raphael75

Active Member
Licensed User
Longtime User
You can try this:

B4X:
Sub Process_Globals
   Dim BTAdmin As BluetoothAdmin
End Sub

Sub Activity_Create(FirstTime As Boolean)
   If FirstTime Then
      BTAdmin.Initialize("BTAdmin")
   End If
End Sub

Sub Activity_Pause (UserClosed As Boolean)
   If UserClosed = True Then
      BTAdmin.Disable
   End If
End Sub

If you already have declared a BluetoothAdmin object in Process_Globals, you don't need to create a new one, you can use the one you have.
 
Upvote 0

pawel2420

Member
Licensed User
Longtime User
Galayxy Y has two buttons "Button 1" and "Button 2" that can ends the program.
If I press the "Button 1" The value of the variable UserClosed in the Activity_Pause is False.
If I press the "Button 2" the variable UserClosed is True.
How to disconnect the Bluetooth connection when user terminates the application by pressing "Button 1" ? gakaxy.JPG
 
Upvote 0

pawel2420

Member
Licensed User
Longtime User
Thank you very much for your help.
Now I understand everything. Indeed, the Home button does not stop the application.
 
Upvote 0
Top