Android Question Problem with WaitFor and CallSub (service)

Mike1970

Well-Known Member
Licensed User
Hi guys,
i've a problem.
I've this in the Activity_Create

B4X:
Dim r As ResultSet = Starter.FileManager1.SQL1.ExecQuery("SELECT RowID FROM xxx")
If r.RowCount < 7903 Then 'se il DB è vuoto
       Wait For (CallSub2(HeavyTasks, "Add", Array As Object("xxx", "ALL", True))) Complete
End If
r.Close


Then, in the Service Module named "HeavyTasks" i've this:

B4X:
Public Sub Add(Params() As Object) As ResumableSub
    'Type 0, Input 1, Sync 2
    queue.Add(CreateMap("Tipo":Params(0), "Input":Params(1)))
    Log(queue)
 
    If Not(Downloading) Then
        Wait For (DownloadDB(Params(2))) Complete (r As Boolean)
    End If
 
    Return r
End Sub

Public Sub DownloadDB(Sync As Boolean) As ResumableSub
    ... do things ...
    Return True
End Sub

The problem is that the "Add" sub in the HeavyTasks module is NEVER fired, and the app deadlock there...
If i use CallSubDelayed it works, but i can't use waitfor...

Thanks in advance
 

Mike1970

Well-Known Member
Licensed User
Everything will be simpler if you use B4XPages.
It is already a complex project (for me) i'm waiting for a bit of time to learn b4xpages.
At the moment it is unconvenient to port it.


2. What exactly are you doing in the "heavy task"?
I'm downloading and storing big number of rows in a db (8000+)


3. Why are you doing it in a service? It will not have any effect on the performance.
I did a combination of the suggetions in this thread i opened some days ago:
 
Upvote 0

Mike1970

Well-Known Member
Licensed User
No reason to use a service. Will not help.

The answer was given in the second post. You should use Wait For with a non query batch. Everything will happen in the background.
Yes infact i was trying to move the subs in a class instead of a service.
 
Upvote 0
Top