Android Question Job1.Download2 -> sending message to waiting queue of uninitialized activity (submitjob)

KMatle

Expert
Licensed User
Hi guys,

I got stuck with this little problem (there are some similar threads but nothing helped).

Using B4A 3.80

B4X:
Dim Job1 As HttpJob
    Job1.Initialize("CheckDevice", Me)
    Job1.Download2("http://www.xxxx.yyy/register/register.php", _
      Array As String("Action", "CheckRegister", "Imei", imei, "Mail", RegMail.Text))

in Activity_Create(FirstTime As Boolean)

works perfect.

But when I move it to a sub the logs show "sending message to waiting queue of uninitialized activity (submitjob)" and JobDone is not called.

Of course I tried to DIM Job1 in Globals but this didn't work either.

For sure a simple thing but I need a push in the right direction.
 

DonManfred

Expert
Licensed User
B4X:
Job1.Initialize("CheckDevice", Me)
ME is the Activity the job is called... probably your activity with the sub... Did you dim and initialize the job in your sub in an other way?

What´s the content your your sub?
 
Upvote 0

KMatle

Expert
Licensed User
Here's the code (simplified):

This works

B4X:
Sub Activity_Create(FirstTime As Boolean)
 
    Dim Job1 As HttpJob
    Job1.Initialize("CheckDevice", Me)
    Job1.Download2("http://www.xxxx.yyy/register/register.php", _
      Array As String("Action", "CheckRegister", "Imei", imei, "Mail", RegMail.Text))
 
End Sub
 
Sub JobDone (Job As HttpJob)
 
...
 
End Sub

This doesn't work for the first time (with the message above):

B4X:
Sub Activity_Create(FirstTime As Boolean)
   CheckDev
End Sub
 
 
 
Sub JobDone (Job As HttpJob)
...
 
End Sub
 
Sub CheckDev
 
    Dim Job1 As HttpJob
    Job1.Initialize("CheckDevice", Me)
    Job1.Download2("http://www.xxxx.yyy/register/register.php", _
      Array As String("Action", "CheckRegister", "Imei", imei, "Mail", RegMail.Text))
 
 
 
End Sub
 
Upvote 0

KMatle

Expert
Licensed User
Here's the code.
B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

   
   
    Private Button1 As Button
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("1")
    'just a button to trigger
   
   
   
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub
Sub JobDone(Job As HttpJob)
    ProgressDialogHide
    If Job.Success Then
        Dim res As String
        res = Job.GetString
        Log("Response from server: " & res)
        Dim parser As JSONParser
        parser.Initialize(res)
       
    Else
        ToastMessageShow("Error: " & Job.ErrorMessage, True)
    End If
    Job.Release
End Sub
Sub checkd
    Dim Job1 As HttpJob
    Job1.Initialize("CheckDevice", Me)
    Job1.Download2("http://www.basic4ppc.com/print.php", _
      Array As String("first key", "first value :)", "second key", "value 2"))
End Sub


Sub Button1_Click
    checkd
End Sub

Log:

B4X:
** Activity (main) Resume **
** Service (service1) Destroy **
** Service (service1) Create **
** Service (service1) Start **
Connected to B4A-Bridge (Wifi)
Installing file.
** Activity (main) Pause, UserClosed = false **
PackageAdded: package:b4a.example
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
sending message to waiting queue of uninitialized activity (submitjob)
** Service (httputils2service) Create **
** Service (httputils2service) Start **
Response from server: POST variables:

array(0) {
}


GET variables:

array(2) {
  ["first_key"]=>
  string(14) "first value :)"
  ["second_key"]=>
  string(7) "value 2"
}
** Activity (main) Create, isFirst = false **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (main) Create, isFirst = false **
** Activity (main) Resume **


By the way: I wonder why every example about httputils(2) is placed in Activity_Create(FirstTime AsBoolean) ONLY. Is there a special reason for it?

This code (I call www.basic4ppc.com/print.php copied from Erels httputils2 example) only works from the 2nd call. At call #1 the message above occurs and I don't have a clue.

There is a Layout with a simple button to trigger checkd.
 

Attachments

  • Testapp.zip
    7.3 KB · Views: 128
Upvote 0

KMatle

Expert
Licensed User
Problem solved:

@Erel : When I test an app using httputils2 and set some breakpoints arround initializing the httpjob then the behaviour occurs (doesn't come back to job done & message is logged but works after the 1+n'th try). Seems that this kind of process doesn't want any interruption.

Without breakpoints between, it works without any problems.
 
Upvote 0

KMatle

Expert
Licensed User
I used "Debug (legacy)"

  1. See picture (I set breakpoints to subs: JobDone , checkd and button1_click
  2. After install press the button
  3. Step trough debugger with "Step to the next line F8" (I used my mouse to click it)
  4. After Job1.Download2 is executed, the message "sending message to waiting queue of uninitialized activity (submitjob)" occurs.
    b4a_httputils2.JPG
 
Upvote 0
Top