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

Discussion in 'Android Questions' started by CanguroCode, Apr 19, 2015.

  1. CanguroCode

    CanguroCode Active Member Licensed User

    How i can use JobDone in a Class like this:


    Code:
    '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
     

    Attached Files:

    Last edited: Apr 19, 2015
  2. DonManfred

    DonManfred Expert Licensed User

    make sure to call downloadInfo.
    The code looks correct
    Maybe put some log-commands to see where it stops...
     
  3. CanguroCode

    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
     

    Attached Files:

  4. DonManfred

    DonManfred Expert Licensed User

    your code works here
    Code:
    Server response: [{"name":"Mexico"}]
    Code:
    '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
     
    Last edited: Apr 19, 2015
    CanguroCode likes this.
  5. CanguroCode

    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
     
  6. CanguroCode

    CanguroCode Active Member Licensed User

  7. CanguroCode

    CanguroCode Active Member Licensed User

    Yes, it was my mistake, I was running with breakpoints and line by line and never saw the entry into the method.

    Thanks for the interest!
     
    DonManfred likes this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice