Hello, i am using part of this code to populate a customlistview and download a list of images which the dimensions of the downloaded images are maximum 100x100px and the size is maximum size is 10kb, most of them are 4kb.
The images show in the customlistview are only 60x60dip.
If i download only 20/30 images the memory usage drop to 40mb + - (which is still alot)
with 100/150 images the memory used it about 110mb and up!
I tried to fix but no success, any hint please?
Thanks
Here the code code:
The images show in the customlistview are only 60x60dip.
If i download only 20/30 images the memory usage drop to 40mb + - (which is still alot)
with 100/150 images the memory used it about 110mb and up!
I tried to fix but no success, any hint please?
Thanks
Here the code code:
B4X:
#Region Service Attributes
#StartAtBoot: False
#End Region
Sub Process_Globals
Private cache As Map
Private tasks As Map
Private ongoingTasks As Map
End Sub
Sub Service_Create
tasks.Initialize
cache.Initialize
ongoingTasks.Initialize
End Sub
Sub Service_Start (StartingIntent As Intent)
End Sub
Sub Service_Destroy
End Sub
Sub Download (ImageViewsMap As Map)
For i = 0 To ImageViewsMap.Size - 1
tasks.Put(ImageViewsMap.GetKeyAt(i), ImageViewsMap.GetValueAt(i))
Dim link As String = ImageViewsMap.GetValueAt(i)
If cache.ContainsKey(link) Then
Dim iv As ImageView = ImageViewsMap.GetKeyAt(i)
iv.SetBackgroundImage(cache.Get(link))
Else If ongoingTasks.ContainsKey(link) = False Then
ongoingTasks.Put(link, "")
Dim j As HttpJob
j.Initialize(link, Me)
j.Download(link)
End If
Next
End Sub
Sub JobDone(Job As HttpJob)
ongoingTasks.Remove(Job.JobName)
If Job.Success Then
Dim bmp As Bitmap = Job.GetBitmap
Log(Job.GetBitmap)
cache.Put(Job.JobName, bmp)
Log(cache.Put(Job.JobName, bmp))
If tasks.IsInitialized Then
For i = 0 To tasks.Size - 1
Dim link As String = tasks.GetValueAt(i)
If link = Job.JobName Then
Dim iv As ImageView = tasks.GetKeyAt(i)
iv.SetBackgroundImage(bmp)
If ongoingTasks.Size=0 Then StopService("imagedownloader2")
End If
Next
End If
Else
Log("Error downloading image: " & Job.JobName & CRLF & Job.ErrorMessage)
End If
Job.Release
End Sub
Sub ActivityIsPaused
tasks.Clear
End Sub
Public Sub ClearCache
cache.Clear
Log("clean")
End Sub