Hello everyone.
Maybe someone can help with advice. I am developing a chat. I want that when the application starts, a request is sent and received a JSON file with all messages in order to update all chats. But while this function is being executed, the interface stops responding to clicks. I found this class
www.b4x.com
but it could not help me (the interface is still blocked)
I initialize the class when the application starts
then I create two methods
If you believe the logs, then Sub Task_Done is called before sub Task completes its work.
Testing in release mode
Maybe someone can help with advice. I am developing a chat. I want that when the application starts, a request is sent and received a JSON file with all messages in order to update all chats. But while this function is being executed, the interface stops responding to clicks. I found this class
Background Task - Run a Sub in background thread without blocking the UI (Asynchronous)
Hi All, UPDATED - You can add Parameters (maximum 2) to your task (You can also add as many variable as you need with declaring them as global variables. So you can use them in your BG sub) UPDATED 2 - You can return a result to Sub_Done event. See Example below...
but it could not help me (the interface is still blocked)
I initialize the class when the application starts
B4X:
Dim myBGTask As BackgroundTask
myBGTask.Initialize("Task", Me, Array())
then I create two methods
B4X:
Sub Task
Log("******************************Task******************************")
Dim job1 As HttpJob
job1.Initialize("UpdateAllMessages", Me)
'Send a GET request
Try
Dim mmap As Map
mmap.Initialize
mmap.Put("Email", encode(mailfromdb))
mmap.Put("Password", encode(passwordfromdb))
job1.PostMultipart(rdcLingGetChat, mmap, Null)
Catch
job1.ErrorMessage = "Error"
End Try
Wait For (job1) JobDone(job1 As HttpJob)
If job1.Success Then
If job1.JobName = "UpdateAllMessages" Then
Log("GetChatJSON")
Dim res As String
res = job1.GetString
Log($"Result: ->${res}<-"$)
Log("Back from Job:" & job1.JobName )
Dim parser As JSONParser
parser.Initialize(res)
Dim rootGetChatJSON As List = parser.NextArray
For Each colroot As Map In rootGetChatJSON
Dim user_id As String = colroot.Get("user_id")
Dim FirstName As String = colroot.Get("FirstName")
Dim text As String = colroot.Get("text")
Dim time As String = colroot.Get("time")
'some sql logic
Next
End If
End If
job1.Release
End Sub
Sub Task_Done
Log("End Task")
End Sub
If you believe the logs, then Sub Task_Done is called before sub Task completes its work.
Testing in release mode