Android Question [SOLVED] How call JobDone Method in a Class

CanguroCode

Active Member
Licensed User
How i can use JobDone in a Class like this:


B4X:
'Class module
Sub Class_Globals
    Private    labelLocal As Label
End Sub

'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize (labelTemp As Label)

    labelLocal=labelTemp

End Sub

Public Sub downloadInfo ' i call this method from a Button1
    ProgressDialogShow("Getting country")
    remoteQuery("SELECT name FROM countries WHERE id='MX'", "name")
End Sub

Private Sub remoteQuery(query As String, nombreJob As String)
    Dim job As HttpJob
    job.Initialize(nombreJob,Me )
    job.PostString("http://www.basic4ppc.com/android/countries.php", query)

End Sub

Sub JobDone(Job As HttpJob)

  ProgressDialogHide
    If Job.Success Then
        Dim res As String
        res=Job.GetString
        Log("Server response: " & res)
        Dim parser As JSONParser
        parser.Initialize(res)

        Select Job.JobName
            Case "name"
                Dim l As List
                l= parser.NextArray
                If l.Size = 0 Then
                    labelLocal.Text="Not download name"
                Else
                    Dim m As Map
                    m= l.Get(0)
                    labelLocal.Text= m.Get("name")
           
                End If
                           
        End Select

    Else
        ToastMessageShow("Error: " & Job.ErrorMessage,True)
    End If

    Job.Release   
End Sub
I thought it was that way, but not executed Job Done.
What am I wrong?


I found only one similar to this thread but no solution.
http://www.b4x.com/android/forum/threads/httputils2-doesnt-call-jobdone-in-classes.26360/

Edit: It is solved. It was my mistake, I was running with breakpoints and line by line and never saw the entry into the method. For the triggers of the event JobDone, this can't be tracking in this way.

But if the project runs without any breakpoint works well, also can be checked using logs or breakpoints within jobdone.

@DonMandFred Thanks for your help and interest.

PD: Attached project already running
 

Attachments

Last edited:

CanguroCode

Active Member
Licensed User
Thanks for your answer. Yes, I'm sure I'm calling the method. I attached the project where I'm doing testing and log. I hope you can help me. thank you very much.

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 **
** Activity (main) Pause, UserClosed = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
getExtractedText on inactive InputConnection
getTextBeforeCursor on inactive InputConnection
getSelectedText on inactive InputConnection
getTextAfterCursor on inactive InputConnection
 

Attachments

DonManfred

Expert
Licensed User
your code works here
B4X:
Server response: [{"name":"Mexico"}]
B4X:
'Class module
Sub Class_Globals
    Private    labelLocal As Label
End Sub

'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize (labelTemp As Label)

    labelLocal=labelTemp

End Sub

Public Sub downloadInfo ' i call this method from a Button1
    Log("class:downloadinfo")
    ProgressDialogShow("Getting country")
  remoteQuery("SELECT name FROM countries WHERE id='MX'", "name")
End Sub

Private Sub remoteQuery(query As String, nombreJob As String)
    Log("class:remoteQuery")
  Dim job As HttpJob
  job.Initialize(nombreJob,Me )
  job.PostString("http://www.basic4ppc.com/android/countries.php", query)
End Sub

Sub JobDone(Job As HttpJob)
    Log("class:JobDone("&Job.GetString&")")
  ProgressDialogHide
    If Job.Success Then
        Dim res As String
        res=Job.GetString
        Log("Server response: " & res)
        Dim parser As JSONParser
        parser.Initialize(res)
       
        Select Job.JobName
            Case "name"
                Dim l As List
                l= parser.NextArray
                If l.Size = 0 Then
                    labelLocal.Text="Not download name"
                Else
                    Dim m As Map
                    m= l.Get(0)
                    labelLocal.Text= m.Get("name")
                   
                End If
                                   
        End Select
       
    Else
        ToastMessageShow("Error: " & Job.ErrorMessage,True)
    End If
       
    Job.Release           
End Sub
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (main) Resume **
class:downloadinfo
class:remoteQuery
** Service (httputils2service) Create **
** Service (httputils2service) Start **
class:JobDone([{"name":"Mexico"}])
Server response: [{"name":"Mexico"}]
 
Last edited:

CanguroCode

Active Member
Licensed User
I just realized my mistake. I was running in "Debug" mode and put a breakpoint in the Button1_Click method then followed line by line and never entered the method jobdone, I thought this was a mistake and I was wrong.

Then I put a breakpoint inside jobdone to see if it was running, it was then that I noticed, yes it was running.

I'll modify the main entrance, will add comments and put the attached draft, in case anyone else has the same question.

Thanks and sorry for my bad bad english
 
Top