Android Question HttpJob when activity_Pause ...

Discussion in 'Android Questions' started by pierrem, Jan 19, 2015.

  1. pierrem

    pierrem Member Licensed User

    Hi,

    When the user activity_pause the app, I want to send through job.postSting this information to a remote server.

    I notice that, because the app is paused, the job is sent to the waiting queue ...

    I found here that to avoid this, it's best to start a service.
    Hereunder is how I do ...

    Is it the correct way ?

    somewhere in the 'main' module of the app :
    Code:
    sub activity_pause()
           callsubdelayed(
    "service","send2Server")
    end Sub
    in the 'service' module of the app :
    Code:
    Sub Process_Globals
       
    Dim endJob As HttpJob
    End Sub

    Sub Service_Destroy
        
    Log("Entering service_Destroy")
    End Sub

    Sub    send2Server()
        
    Log("Entering  send2Server ....")
        endJob.Initialize(
    "jobEnd",Me)
        endJob.PostString(
    "http://myurl","mypayload")
    End Sub

    Sub jobDone(job As HttpJob)
        
    Log("Entering service-jobDone")
        
    If (job.Success) Then
            Service_Destroy
        
    Else
            
    Log("Error on "&job.JobName)
        
    End If
    End Sub
    BTW,
    Should I add in the 'main' module an :
    activity.Finish (if I want the app just no be just paused but definitly terminated)

    ?

    Thanks in advance for yours remarks and comment
    :)
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    You should call StopService(me) to stop the service.

    Your code looks correct.

    You can call Activity.Finish if you want to destroy the activity even if the user presses on the home button.
     
    pierrem 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