Android Question [Solved] Service issues (Issues with Wait for and issues with variables)

Frank.G

Member
Licensed User
Good day,

I have problems with an app that uses a service to poll SMB data every certain time.
For debugging pupose I call the service every 30 sec, but it doesn't make any difference even if only called once.

1.
The SMB routine is called from the main activity once and works as supposed.
But when the service calles the same code (part of the service) it does nothing anymore as soon as the first wait for is reached.
Call from the main
B4X:
StartServiceAt(updater,DateTime.Now+30 * 1000, True)
then in the updater service
B4X:
Sub Service_Start (StartingIntent As Intent)
StartServiceAt(Me,DateTime.Now+30 * 1000, True)
connection
end sub

Sub connection
    SMB.ListFiles(smbdownload_datapath, "*.xls")
    ToastMessageShow("Updating Data", True)
    Log("Service the time now is: " & DateTime.Time(DateTime.Now))
    Wait for SMB_ListCompleted(Url As String, Success As Boolean, Entries() As SMBFile)
    Dim I As Int
    If Not(Success) Then
        co_success = False
        Log( "service " & co_success)
    Else
        co_success = True
        Log("service " & co_success)
        download_count = Entries.Length
        For i = 0 To Entries.length -1
            SMB.DownloadFile(smbdownload_datapath, Entries(i).name, File.DirInternal, Entries(i).name)
            Wait for SMB_DownloadCompleted (Url As String, RemoteFile As String, Success As Boolean)
            If Success = True And download_count = 3 Then
                download_ver = "Letzte data Version " & DateTime.Date(Entries(0).LastModified) & " " & DateTime.Time(Entries(0).LastModified)
                up_success = True
                Log("service " & up_success)
            Else
                up_success = False
                Log("service " & up_success)
            End If
        Next
        old_download_ver = download_ver
    End If
   
    update_success = up_success
    connection_success = co_success
End Sub

So the toast message shows up but the other log messages don't. It seems the the service stops working as soon as >Wait for< is reached.

2.
Global variables defined in the main activity do not show up in the service and vice versa.
Did I understand the defining section wrong ?

Example:
Service
B4X:
Sub Process_Globals
    Public SMB As SMB
end sub
Is unknown by the activity

Activity
B4X:
Sub Process_Globals
    Public SMB As SMB
end sub
Is unknown by the service

How can I set veriables and use them the value in several modules/services at once ?


Maybe someone can point me to the correct direction.

Thanks alot in advance

Frank
 

Frank.G

Member
Licensed User
Good day,

2.
Global variables defined in the main activity do not show up in the service and vice versa.
Did I understand the defining section wrong ?

Example:
Service
B4X:
Sub Process_Globals
    Public SMB As SMB
end sub
Is unknown by the activity

Activity
B4X:
Sub Process_Globals
    Public SMB As SMB
end sub
Is unknown by the service

How can I set veriables and use them the value in several modules/services at once ?


Maybe someone can point me to the correct direction.

Thanks alot in advance

Frank
Ok, found the problem to issue 2 myself.

You have to prefix the variable with the modul you are taking it from :oops:
So maybe i can solve the fist issue also, will keep looking :rolleyes:

Thx anyways and sorry for stupid questions
Frank


EDIT:
Now the service runs without flaws and doesn't stop at the wait for.

It seems that declaring two time the same SMB is not a good thing
After changing it to use the variable of the main everything runs flawless. oh well *facepalm*

Frank
 
Last edited:
Top