A Arturs Member Licensed User Longtime User Nov 8, 2015 #1 Hi I am writing an aplication with three activities. In each of them I need to use bluetooth,serial,Async... so it is necessary to use service module. I decided to use some part of code of File Transfer example (very good example) https://www.b4x.com/android/forum/th...nd-and-receive-files-with-asyncstreams.30493/ but I have one question related the code In Main File you use StateChanged Event Code: Sub Admin_StateChanged (NewState As Int, OldState As Int) UpdateUI End Sub but In Service Module the same Event Code: Sub admin_StateChanged (NewState As Int, OldState As Int) If NewState = admin.STATE_ON Then serial1.Listen2("na", uuid) End Sub In which mode your service mode works ? Which Event will have higher priority ? Which will be first ? i mean service in foregroundmode Regards Artur Last edited: Nov 8, 2015
Hi I am writing an aplication with three activities. In each of them I need to use bluetooth,serial,Async... so it is necessary to use service module. I decided to use some part of code of File Transfer example (very good example) https://www.b4x.com/android/forum/th...nd-and-receive-files-with-asyncstreams.30493/ but I have one question related the code In Main File you use StateChanged Event Code: Sub Admin_StateChanged (NewState As Int, OldState As Int) UpdateUI End Sub but In Service Module the same Event Code: Sub admin_StateChanged (NewState As Int, OldState As Int) If NewState = admin.STATE_ON Then serial1.Listen2("na", uuid) End Sub In which mode your service mode works ? Which Event will have higher priority ? Which will be first ? i mean service in foregroundmode Regards Artur
Erel B4X founder Staff member Licensed User Longtime User Nov 8, 2015 #2 All the events should be moved to the service. You can then use CallSub or CallSubDelayed to update the UI. Upvote 0
All the events should be moved to the service. You can then use CallSub or CallSubDelayed to update the UI.
A Arturs Member Licensed User Longtime User Nov 8, 2015 #3 Ok but In File transfer example you have the events from Bluetooth in service module and Main ? Why did you do it ? This is Why I asked about priority etc and another question In Activity Create you get List of paired device (friendly device) Code: If FirstTime Then StartService(FileTranser) btDevices.Initialize admin.Initialize("Admin") CC.Initialize("CC") 'add the already paired devices to the list 'later the user can search for new devices Dim serial1 As Serial serial1.Initialize("") Dim pairedDevices As Map = serial1.GetPairedDevices For i = 0 To pairedDevices.Size - 1 Dim nm As NameAndMac nm.Initialize nm.mac = pairedDevices.GetValueAt(i) nm.name = pairedDevices.GetKeyAt(i) btDevices.Add(nm) Next End If but btDevice.size is always 0 until the bluetooth module is not enabled. If you enable bluetooth module before starting FileTransfer aplication then everything is Ok. Is it a bug ? Last edited: Nov 8, 2015 Upvote 0
Ok but In File transfer example you have the events from Bluetooth in service module and Main ? Why did you do it ? This is Why I asked about priority etc and another question In Activity Create you get List of paired device (friendly device) Code: If FirstTime Then StartService(FileTranser) btDevices.Initialize admin.Initialize("Admin") CC.Initialize("CC") 'add the already paired devices to the list 'later the user can search for new devices Dim serial1 As Serial serial1.Initialize("") Dim pairedDevices As Map = serial1.GetPairedDevices For i = 0 To pairedDevices.Size - 1 Dim nm As NameAndMac nm.Initialize nm.mac = pairedDevices.GetValueAt(i) nm.name = pairedDevices.GetKeyAt(i) btDevices.Add(nm) Next End If but btDevice.size is always 0 until the bluetooth module is not enabled. If you enable bluetooth module before starting FileTransfer aplication then everything is Ok. Is it a bug ?
Erel B4X founder Staff member Licensed User Longtime User Nov 9, 2015 #4 Arturs said: Ok but In File transfer example you have the events from Bluetooth in service module and Main ? Why did you do it ? Click to expand... It uses two BluetoothAdmin objects. One in the main module and one in the service. I think that it is better to use one, only in the service. Arturs said: but btDevice.size is always 0 until the bluetooth module is not enabled. If you enable bluetooth module before starting FileTransfer aplication then everything is Ok. Is it a bug ? Click to expand... Yes. It doesn't handle this case. Upvote 0
Arturs said: Ok but In File transfer example you have the events from Bluetooth in service module and Main ? Why did you do it ? Click to expand... It uses two BluetoothAdmin objects. One in the main module and one in the service. I think that it is better to use one, only in the service. Arturs said: but btDevice.size is always 0 until the bluetooth module is not enabled. If you enable bluetooth module before starting FileTransfer aplication then everything is Ok. Is it a bug ? Click to expand... Yes. It doesn't handle this case.
A Arturs Member Licensed User Longtime User Nov 9, 2015 #5 It uses two BluetoothAdmin objects. One in the main module and one in the service. Click to expand... What about priorities and conflict. Two different object but one device. Yes. It doesn't handle this case. Click to expand... Will it be improved in next version of B4A Upvote 0
It uses two BluetoothAdmin objects. One in the main module and one in the service. Click to expand... What about priorities and conflict. Two different object but one device. Yes. It doesn't handle this case. Click to expand... Will it be improved in next version of B4A
Erel B4X founder Staff member Licensed User Longtime User Nov 10, 2015 #6 Both StateChanged events will be raised as this event comes from a broadcasted intent. As I said, it will be simpler to use a single object in the service module. Arturs said: Will it be improved in next version of B4A Click to expand... It has nothing to do with B4A version. It is just a small example. You can modify it as you need. Upvote 0
Both StateChanged events will be raised as this event comes from a broadcasted intent. As I said, it will be simpler to use a single object in the service module. Arturs said: Will it be improved in next version of B4A Click to expand... It has nothing to do with B4A version. It is just a small example. You can modify it as you need.