Android Question sending message to waiting queue of uninitialized activity (submitjob)

Ilya G.

Active Member
Licensed User
Longtime User
Hello, my program sends authorization data at startup. But on the first run after installing the program, I always get this error. I think this happens because the Receiver has not started yet, what should I do in this case?

B4X:
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create (first time) **
<- (MyMap) {option=login, name=admin, password=gGnCtR3TbqiY9HX*****}
Call B4XPages.GetManager.LogEvents = True to enable logging B4XPages events.
** Activity (main) Resume **
sending message to waiting queue of uninitialized activity (submitjob)
*** Receiver (httputils2service) Receive (first time) ***
 

Ilya G.

Active Member
Licensed User
Longtime User
B4XMainPage:
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("main_0")

    If UT.GetPref("user") <> "" Then
        Login.SetText(UT.GetPref("user"))
    End If

    If UT.GetPref("pass") <> "" Then
        Password.SetText(UT.GetPref("pass"))
        AuthButton_Click
    End If
End Sub

B4XMainPage:
Sub AuthButton_Click
    Wait For (UT.ExecHTTP(CreateMap("option":"login", "name":Login.GetText2, "password":Password.GetText2))) Complete (result_list As List)

    If result_list.IsInitialized And result_list.Size > 0 Then
        Private value As Map = result_list.Get(0)
        
        If value.ContainsKey("error") Then
            DT.ErrorMessageToast = value.Get("error")
            Return
        End If
        
        UT.PutPref("app_id", value.Get("id"))
        UT.PutPref("user", Login.GetText2)
        UT.PutPref("pass", Password.GetText2)
        UT.PutPref("role", value.Get("role"))
        UT.PutPref("name", value.Get("name"))
        UT.PutPref("phone", value.Get("phone"))

        B4XPages.ShowPageAndRemovePreviousPages("Home")
    Else
        DT.ErrorMessageToast = "Ошибка при подключении к серверу"
    End If
End Sub

Utilites (class):
Sub ExecHTTP (command As Map) As ResumableSub
    Private result As List
    
    command.Put("id", getPref2("app_id", Null))
    
    Private generator As JSONGenerator
    generator.Initialize(command)
    
    Private job As HttpJob
    job.Initialize("", Me)
    job.PostString("*****/mobile_api.php", generator.ToString)
    
    Wait For JobDone (job As HttpJob)
        
    If job.Success Then
        Try
            Private json As JSONParser
            json.Initialize(job.GetString)
            result.Initialize
            result = json.NextArray
        Catch
            LogColor("-> [" & command.Get("option") & "] (error) " & job.GetString, Colors.Red)
        End Try
    Else
        LogColor("-> [" & command.Get("option") & "] (error) " & job.ErrorMessage, Colors.Red)
    End If
        
    job.Release
    Return result
End Sub
 
Upvote 0

Ilya G.

Active Member
Licensed User
Longtime User
What is UT?

Can you reproduce it in a small project?

UT is a small class Utilites where the ExecHTTP function is located. Copying exactly these functions into a separate project for demonstration does not cause such an error.
Can I send you the whole big project with librarys?

B4X:
Sub ExecHTTP (command As Map) As ResumableSub
    Private result As List
    
    Private generator As JSONGenerator
    generator.Initialize(command)
    
    Private job As HttpJob
    job.Initialize("", Me)
    job.PostString("*****/mobile_api.php", generator.ToString)
    
    Wait For JobDone (job As HttpJob)
        
    If job.Success Then
        Try
            Private json As JSONParser
            json.Initialize(job.GetString)
            result.Initialize
            result = json.NextArray
        Catch
            LogColor("-> [" & command.Get("option") & "] (error) " & job.GetString, Colors.Red)
        End Try
    Else
        LogColor("-> [" & command.Get("option") & "] (error) " & job.ErrorMessage, Colors.Red)
    End If
        
    job.Release
    Return result
End Sub
 
Upvote 0

Ilya G.

Active Member
Licensed User
Longtime User
This is not correct.

I think there is no point you add Try-Catch after job.Success
You can add Try before job.PostString

I tried like this, it seems Log(LastException) is not happening

B4X:
Sub ExecHTTP (command As Map) As ResumableSub
    Private result As List
    Private generator As JSONGenerator
    generator.Initialize(command)
    
    Private job As HttpJob
    job.Initialize("", Me)
    Try
        job.PostString("https://*****/mobile_api.php", generator.ToString)
    Catch
        Log(LastException)
    End Try
    Wait For JobDone (job As HttpJob)
        
    If job.Success Then
        Try
            Private parser As JSONParser
            parser.Initialize(job.GetString)
            result.Initialize
            result = parser.NextArray
        Catch
            LogColor("-> [" & command.Get("option") & "] (error) " & job.GetString, Colors.Red)
        End Try
    End If
        
    job.Release
    Return result
End Sub
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
Wait For JobDone (job As HttpJob)
You are missing to pass the job as object
B4X:
Wait For (job) JobDone (job As HttpJob)

There are also other issues with your code.

Try:
B4X:
Sub ExecHTTP (command As Map) As ResumableSub
    Dim result As List
    Try
        Dim job As HttpJob
        job.Initialize("", Me)
        
        Dim generator As JSONGenerator
        generator.Initialize(command)
        
        job.PostString("https://*****/mobile_api.php", generator.ToString)
        Wait For (job) JobDone (job As HttpJob)
        If job.Success Then
            Dim parser As JSONParser
            parser.Initialize(job.GetString)
            result.Initialize
            result = parser.NextArray
        Else
            LogColor("-> [" & command.Get("option") & "] (error) " & job.ErrorMessage, xui.Color_Red)
        End If       
    Catch
        LogColor(LastException.Message, xui.Color_Red)
    End Try       
    job.Release
    Return result
End Sub
 
Last edited:
Upvote 0

Ilya G.

Active Member
Licensed User
Longtime User
Not happening, only black "sending message to waiting queue of uninitialized activity (submitjob)" in log
 
Upvote 0

PJLPJLPJL

Member
Licensed User
Which version of android are you having problems with?
When we upgraded to B4A 12 (the version which introduced Receivers for Android 13) with targetSDK updated to 31, I encountered this same problem using OKHttp2 on devices running Android 11 and Android 7.1 - the solution was to use the old version of OKHttp2 (which uses a service rather than a receiver); this is still working very well on these older devices.
I expect to have to re-upgrade to the "proper" receiver-based OKHttp2 library when I upgrade my devices.
 
Upvote 0

Ilya G.

Active Member
Licensed User
Longtime User
Which version of android are you having problems with?
When we upgraded to B4A 12 (the version which introduced Receivers for Android 13) with targetSDK updated to 31, I encountered this same problem using OKHttp2 on devices running Android 11 and Android 7.1 - the solution was to use the old version of OKHttp2 (which uses a service rather than a receiver); this is still working very well on these older devices.
I expect to have to re-upgrade to the "proper" receiver-based OKHttp2 library when I upgrade my devices.

I have the same devices, Samsung A40 with android 11 and BlueStacks App Player 5.10.220 with android 7.1
 
Upvote 0
Top