I'm using the Bluetooth Chat example, and I try to add another activity module/layout called Page3. In Page3 I want to use the Bluetooth connection with AsyncStreams, but I get error message "Connection is broken".
In the ChatActivity layout I press a button BtnPage3 in order to open the new layout Page3, with this code in the ChatActivity module:
In Page 3 I have the code:
If I don't close AStream before leaving ChatActivity module, I don't get error message "Connection is broken", but the connection in Page3 doesn't work correctly, that means many bytes are not received (it looks like half of the bytes go to Sub AStream_NewData in ChatActivity module, and the other half go to Sub AStream3_NewData in Page3 module).
I also tried to use directly the ChatActivity.AStream object in the Page3 module instead of declaring the new AStream3 object, but it is not accepted to write Sub ChatActivity.AStream_NewData (Buffer() As Byte).
How can I use AsyncStreams in different activity modules in the same application?
In the ChatActivity layout I press a button BtnPage3 in order to open the new layout Page3, with this code in the ChatActivity module:
B4X:
Sub BtnPage3_Click
Page3.AStream3 = AStream ' AStream3 is declared in Process_Globals in Page3 module
AStream.Close ' Close AsyncStreams in ChatActivity module
StartActivity(Page3) ' Open Page3
End Sub
In Page 3 I have the code:
B4X:
Sub Process_Globals
Dim AStream3 As AsyncStreams
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("LayoutPage3")
If AStream3.IsInitialized = False Then
AStream3.Initialize(Main.serial1.InputStream, Main.serial1.OutputStream, "AStream3")
End If
End Sub
Sub AStream3_NewData (Buffer() As Byte)
[...]
If I don't close AStream before leaving ChatActivity module, I don't get error message "Connection is broken", but the connection in Page3 doesn't work correctly, that means many bytes are not received (it looks like half of the bytes go to Sub AStream_NewData in ChatActivity module, and the other half go to Sub AStream3_NewData in Page3 module).
I also tried to use directly the ChatActivity.AStream object in the Page3 module instead of declaring the new AStream3 object, but it is not accepted to write Sub ChatActivity.AStream_NewData (Buffer() As Byte).
How can I use AsyncStreams in different activity modules in the same application?