I have a b4a project that contains 2 activities, Main and Download, that main activity contains a button that calls the second activity, the 2nd activity has 3 imageviews , here's the code :
With a high speed internet connection there's no problem, but when we have a middle or low speed connection, when the image download is in progress, because it takes a while to get the image, if the user push the back button the app returns to Main activity but suddenly it jump to Download activity until the download is finished.
I want to know is there any way to cancel the download process in this scenario?
Tanx in advance
B4X:
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim imgDownload1, imgDownload2, imgDownload3 As ImageView
Dim ImageJob As HttpJob
End Sub
Sub Activity_Create(FirstTime As Boolean)
ImageJob.ContentType = ""
ImageJob.Initialize("GetImage", Me)
imgDownload1.Initialize("")
Activity.AddView(imgDownload1,0,0, 100dip, 100dip)
imgDownload1.Gravity = Gravity.FILL
imgDownload2.Initialize("")
Activity.AddView(imgDownload2,0,100dip, 100dip, 100dip)
imgDownload2.Gravity = Gravity.FILL
imgDownload3.Initialize("")
Activity.AddView(imgDownload3,0,200dip, 100dip, 100dip)
imgDownload3.Gravity = Gravity.FILL
ProgressDialogShow("Please Wait...")
Dim i As Int
For i = 1 To 3
Dim ImageJob As HttpJob
ImageJob.ContentType = ""
ImageJob.Initialize("GetMainImage", Me)
Dim strFileName As String
ImageJob.ExtraData1 = i
Select Case ImageJob.ExtraData1
Case "1"
ImageJob.Download2("http://fronttowardsgamer.com/wp-content/uploads/2011/12/microsoft-logo.jpg", Array As String("id", 1))
Case "2"
ImageJob.Download2("http://blog.tmcnet.com/blog/rich-tehrani/uploads/old-microsoft-logo.jpg", Array As String("id", 1))
Case "3"
ImageJob.Download2("http://blog.tmcnet.com/blog/rich-tehrani/uploads/old-microsoft-logo.jpg", Array As String("id", 1))
End Select
Next
End Sub
Sub JobDone (Job As HttpJob)
If Job.Success = True Then
Select Job.JobName
Case "GetMainImage"
Try
Select Case Job.ExtraData1
Case "1"
imgDownload1.Bitmap = Job.GetBitmap
Case "2"
imgDownload2.Bitmap = Job.GetBitmap
Case "3"
imgDownload3.Bitmap = Job.GetBitmap
ProgressDialogHide
End Select
Catch
ToastMessageShow("Error 1: " & Job.ErrorMessage & CRLF & LastException.Message, True)
End Try
End Select
Job.Release
End If
End Sub
With a high speed internet connection there's no problem, but when we have a middle or low speed connection, when the image download is in progress, because it takes a while to get the image, if the user push the back button the app returns to Main activity but suddenly it jump to Download activity until the download is finished.
I want to know is there any way to cancel the download process in this scenario?
Tanx in advance