Android Question File Transfer example questions

Arturs

Member
Licensed User
Longtime User
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

B4X:
Sub Admin_StateChanged (NewState As Int, OldState As Int)
UpdateUI
End Sub
but In Service Module the same Event


B4X:
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:

Arturs

Member
Licensed User
Longtime User
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)

B4X:
    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:
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Ok but In File transfer example you have the events from Bluetooth in service module and Main ?
Why did you do it ?
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.

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 ?
Yes. It doesn't handle this case.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
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.

Will it be improved in next version of B4A
It has nothing to do with B4A version. It is just a small example. You can modify it as you need.
 
Upvote 0
Top