Which is the best solution to completely run async operations while querying a db? And leave the UI completely responsive.
The operation I need to run is a combination of querying db and very large for and while cycles.
I tried the asyncTask library but it crashes randomly, this is related with querying the db from the asyncTask_DoInBackground method. If it wasn't from this random crashes it would be the perfect solution, this library leave the UI 100% responsive
The "wait for" doesn't work, I use it like this post suggests, but still freezes the UI.
I can't paste here all the code, but it looks something like this:
(This code is just to get a rough idea on how the subs are distributed)
The "runThisCompletelyAsync" doesn't change the UI, it rather write or not the db, but in the process it query the db, read files and run very long for cycles.
Does someone have an idea on how to perform this operation completely async?
The operation I need to run is a combination of querying db and very large for and while cycles.
I tried the asyncTask library but it crashes randomly, this is related with querying the db from the asyncTask_DoInBackground method. If it wasn't from this random crashes it would be the perfect solution, this library leave the UI 100% responsive
The "wait for" doesn't work, I use it like this post suggests, but still freezes the UI.
I can't paste here all the code, but it looks something like this:
(This code is just to get a rough idea on how the subs are distributed)
B4X:
'From the service module
Sub runThisCompletelyAsync(value As int,value2 As string,value3 As int)
if MySub1(value) then
'Do something
else if MySub2(value2) then
if value2 = "hello" then
'Do something
writeDB(value,value2)
else
MySub4(value)
End if
else
Dim b As int = MySub3(value3)
for i=0 to b
'Do something
'Read file from DirInternal
next
writeDB(value,value2)
end if
End Sub
Sub MySub1(val As int) As boolean
'Query db synchronously
End Sub
Sub MySub2(val As string) As boolean
'Query db synchronously
End Sub
Sub MySub3(val As int) As int
'Query db synchronously
End Sub
Sub MySub4(val As int)
for i=0 to val
'Do something
next
End Sub
Sub writeDB(val As int,val2 As string)
'Write DB async
End Sub
The "runThisCompletelyAsync" doesn't change the UI, it rather write or not the db, but in the process it query the db, read files and run very long for cycles.
Does someone have an idea on how to perform this operation completely async?