Problem With Access Job - HttpJob

rclatorre

Member
Licensed User
Longtime User
I have a problem with HttpJob

Here's the scenario:

1.I have two activities:
a.La first displays the list of articles in a magazine and allows the choice
b.La second displays the selected item and download an image.

2.The problem occurs when after entering the second activity and having sent a Job to download an image, step back to the first activity before the Job ends.

The job apparently still in process and tries to access a position under a variable that no longer exists.

This is the code of the job of the second activity:

Call the Job
B4X:
.....
image_top_url=m.Get("image_top_url")
            If image_top_url.Length>0 Then
               Dim job1 As HttpJob
               job1.Initialize("Job1", Me)
               job1.Index = i
               job1.Tag = "Top"
               job1.Download(m.Get("image_top_url"))
            End If
....


Job
B4X:
Sub JobDone (Job As HttpJob)
   Log("JobName = " & Job.JobName & ", Success = " & Job.Success)
   
   If    Pan.Length > 0 Then
      If Job.Success = True Then
         Dim pan1 As Panel
         pan1.Initialize("")
         pan1=Pan(Job.Index)

         Select Job.Tag 
            Case  "Top"
               Pan(Job.Index).GetView(3).SetBackgroundImage(Job.GetBitmap)
            Case  "Bottom"
               Pan(Job.Index).GetView(7).SetBackgroundImage(Job.GetBitmap)
         End Select
         
      
      Else
         Log("Error: " & Job.ErrorMessage)
         ToastMessageShow("Error: " & Job.ErrorMessage, True)
      End If
      Job.Release
   End If

End Sub

The query is no way to kill Job called in the second activity in a way that is no longer running.


Thanks

Roberto
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
As I see it you have two options:
1. Add a boolean global variable named Abort to HttpJob and change Complete sub to:
B4X:
Public Sub Complete (id As Int)
 If Abort = True Then
  Release
  Return
 End If
   taskId = id
   CallSubDelayed2(target, "JobDone", Me)
End Sub

2. Use a service to handle all the tasks. This will probably be simpler.
 
Upvote 0
Top