Android Question Sub JobDone is not calling

Discussion in 'Android Questions' started by Juzer Hussain, Jul 7, 2015.

  1. Juzer Hussain

    Juzer Hussain Active Member Licensed User

    Hi Erel,

    I am facing strange issues as reported by others too with procedure SubJobDone.It never fires on first attempt.On second(or third etc) click it calls but I loose global values in other forms.If i put breakpoint inside SubJobDone it sometimes stops but most of the time does not.I am using rapid debugger.I have tried to search forum but could not get sure shot answer.can you pls help.Below is my code.

    Job_GetUser.Initialize("Job_GetUser",Me)
    Job_GetUser.Download2(ServerURL2,Array As String("Query","Select * from xxx Where UserID='" & txtID.text & "' and pwd='" & txtPassword.text & "'"))

    Sub Jobdone (Job As HttpJob)
    If Job.Success=True Then
    Select Job.JobName
    Case "Job_GetUser"
    Dim parser As JSONParser
    Dim response As String
    response=Job_GetUser.GetString
    ............etc
     
  2. DonManfred

    DonManfred Expert Licensed User

    Are you sure the sub is NOT called?
    Maybe it is just that the Job.Success is false and so it wont run through your code

    Upload a small project which shows the problem.
     
    ArminKH, lemonisdead and RandomCoder like this.
  3. Juzer Hussain

    Juzer Hussain Active Member Licensed User

    Hi DonManfred,

    Thanks for replying.
    Below is my code.
    I am assigning value to global variable in JobDone.

    Sub btnLogin_Click
    Job_GetUser.Initialize("Job_GetUser",Me)
    Job_GetUser.Download2(ServerURL,Array As String("Query","Select Cmpycode from AppUsers Where UserID='" & txtID.text & "' and pwd='" & txtPassword.text & "'"))
    If gsCmpyCode<>"" Then >>>>>>>>>>>>>>>>>>>>>>>>>break point here
    ---------------------------------------
    Sub Jobdone (Job As HttpJob)
    If Job.Success=True Then
    Select Job.JobName
    Case "Job_GetUser"
    Dim parser As JSONParser
    Dim response As String
    response=Job_GetUser.GetString

    If response.Length<10 Then
    ToastMessageShow("Error: Incorrect User Name/ Password" & Job.ErrorMessage, True)
    End If

    parser.Initialize(response)
    Dim rows As List
    rows=parser.NextArray
    Dim m As Map
    Dim i As Int
    i=0
    m=rows.Get(i)
    gsCmpyCode=m.Get("Cmpycode")
    gsUserID=txtID.text
    If I put breakpoint on If gsCmpyCode<>"" Then it gives me value 1 out of 3 times.I have no clue where is the problem.
    Pls guide me.
    Thanks
    Juzer
     
  4. DonManfred

    DonManfred Expert Licensed User

    in the IDE File Export to zip and upload this zip here!

    Alone with your snippets i cannot help
     
  5. LucaMs

    LucaMs Expert Licensed User


    You can not pretend that gsCmpyCode has changed its value here, immediately after Job_GetUser.Download2; it changes in your jobdone routine
     
    DonManfred and RandomCoder like this.
  6. Juzer Hussain

    Juzer Hussain Active Member Licensed User

    After some digging i got the exact problem. Actually
    After Job_GetUser.Download2(ServerURL,............... I am checking the value of gsCmpyCode immediately.
    This statement should execute after JobDone Routine (where gsCmpyCode is assigned value).It gets executed before that and as such it is blank.
    Pls see same problem reported below.
    http://www.b4x.com/android/forum/threads/how-to-wait-httpjob-execution.50313/

    Can u guide me what to do.
     
  7. Juzer Hussain

    Juzer Hussain Active Member Licensed User

    Shall I put some delay loop. I tried checking Job_GetUser.Complete but no luck.
     
  8. sorex

    sorex Expert Licensed User

    you could use a do while gsCmpyCode<>"" loop but that's bad design and might make your app non-responding.

    your program workflow is not what it should be.
     
    lemonisdead likes this.
  9. RandomCoder

    RandomCoder Well-Known Member Licensed User

    No it is not gold practice to hold the main thread in a delay loop. It wouldn't work anyway because the loop would prevent other events from occurring.
    You have a couple of simple options....
    1. Move the code following the download request into the job.Done routine, it will then run through this code if the download was successful. If unsuccessful you can choose to so something else.
    2. Start a timer and on each tick event check to see if the value of gsCmpyCode has changed. You could count the number of tick events and abort if too many have occurred i.e. timeout.​

    Always try and use events rather than loops!
     
    lemonisdead, DonManfred and LucaMs like this.
  10. LucaMs

    LucaMs Expert Licensed User

    +1
     
  11. Juzer Hussain

    Juzer Hussain Active Member Licensed User

    Thank You "RandomCoder" for elaborate help.
    I moved the code into JobDone and its working fine.

    Thank you guys sorex and LucaMs for replying.
     
Loading...