The error appears whenever I have switched between pages of the app for about 5-6 times.. I have searched the forum but there seems to be no solution to solve the problem??
how you load your bitmaps ? post the relevant part of code if possible
-try using LoadBitmapSample if you loading high res. images
-try recycling the bitmap if its not in use
B4X:
Try
Dim Obj1 As Reflector
Obj1.Target = Thebitmap
Obj1.RunMethod ("recycle")
Catch
log("Error Recycling Bitmap")
End Try
how you load your bitmaps ? post the relevant part of code if possible
-try using LoadBitmapSample if you loading high res. images
-try recycling the bitmap if its not in use
B4X:
Try
Dim Obj1 As Reflector
Obj1.Target = Thebitmap
Obj1.RunMethod ("recycle")
Catch
log("Error Recycling Bitmap")
End Try
For inx = 0 To m.size - 1 'm is the map where I put all the picture address
Dim picv As String = m.Get(inx)
p.Initialize("")
clv.add(p,100%x + 5,link) 'clv is the custom list view
p.LoadLayout("ImageView")
If picv <> Null Then m2.Put(imageview1,picv) 'I use the image downloader to put the image into the imageview
Next
Where should I put the codes for recycling the bitmap???
I try calling activity.finish in Activity_pause, but it didn't help. The memory used up as fast as before.
For inx = 0 To m.size - 1 'm is the map where I put all the picture address
Dim picv As String = m.Get(inx)
p.Initialize("")
clv.add(p,100%x + 5,link) 'clv is the custom list view
p.LoadLayout("ImageView")
If picv <> Null Then m2.Put(imageview1,picv) 'I use the image downloader to put the image into the imageview
Next
Where should I put the codes for recycling the bitmap???
I try calling activity.finish in Activity_pause, but it didn't help. The memory used up as fast as before.
The major problem I think is that the memory doesn't clear up after the close the module (end the activity) because at first the pictures are loaded fine.. I try to close and open and close and open the module, then the memory is used up for about 5-6 times.. Actually they should not store anything after I close them.. Otherwise the problem will never be solved and the memory will eventually used up anyway.. How to clear the memory after the module is close??
the system will automatically release the activity memory if its not in use but its not immediately.
the images are big if you loading them into small imageviews in the CLV you should use LoadBitmapSample it will help to decrease the memory usage
if this images is frequently used in your application i recommend to load them one time and store them in process global variables to stop memory increasing each time you load them
the system will automatically release the activity memory if its not in use but its not immediately.
the images are big if you loading them into small imageviews in the CLV you should use LoadBitmapSample it will help to decrease the memory usage
if this images is frequently used in your application i recommend to load them one time and store them in process global variables to stop memory increasing each time you load them
by saving the bitmap to file (i think you should save it to DirInternalCache instead of re-downloading each time) or try this code to scale the bitmap without saving it
B4X:
Sub CreateScaledBitmap(Original As Bitmap, Width As Int, Height As Int) As Bitmap
Dim r As Reflector
Dim Filter As Boolean =False
Dim b As Bitmap
b = r.RunStaticMethod("android.graphics.Bitmap", "createScaledBitmap", _
Array As Object(Original, Width, Height, Filter), _
Array As String("android.graphics.Bitmap", "java.lang.int", "java.lang.int", "java.lang.boolean"))
Return b
End Sub
by saving the bitmap to file (i think you should save it to DirInternalCache instead of re-downloading each time) or try this code to scale the bitmap without saving it
B4X:
Sub CreateScaledBitmap(Original As Bitmap, Width As Int, Height As Int) As Bitmap
Dim r As Reflector
Dim Filter As Boolean =False
Dim b As Bitmap
b = r.RunStaticMethod("android.graphics.Bitmap", "createScaledBitmap", _
Array As Object(Original, Width, Height, Filter), _
Array As String("android.graphics.Bitmap", "java.lang.int", "java.lang.int", "java.lang.boolean"))
Return b
End Sub
I am not sure about how to use this code... like this??
B4X:
Dim pic as string 'as the picture address
Dim Imageview1 as imageview 'as the image view to show the picture
Imageview1.bitmap = CreateScaledBitmap(pic,Imageview1.width,Imageview1.height)
I am not sure about how to use this code... like this??
B4X:
Dim pic as string 'as the picture address
Dim Imageview1 as imageview 'as the image view to show the picture
Imageview1.bitmap = CreateScaledBitmap(pic,Imageview1.width,Imageview1.height)
1. Remove the reference to HttpUtils2 library.
2. Add HttpUtils2 modules instead.
3. Add this sub to HttpJob:
B4X:
'Returns the response as a bitmap loaded with LoadBitmapSample.
Public Sub GetBitmapSample(Width As Int, Height As Int) As Bitmap
Return LoadBitmapSample(HttpUtils2Service.TempFolder, taskId, Width, Height)
End Sub
4. Modify ImageDownloader to use GetBitmapSample instead of GetBitmap.
1. Remove the reference to HttpUtils2 library.
2. Add HttpUtils2 modules instead.
3. Add this sub to HttpJob:
B4X:
'Returns the response as a bitmap loaded with LoadBitmapSample.
Public Sub GetBitmapSample(Width As Int, Height As Int) As Bitmap
Return LoadBitmapSample(HttpUtils2Service.TempFolder, taskId, Width, Height)
End Sub
4. Modify ImageDownloader to use GetBitmapSample instead of GetBitmap.
In the ImageDownloader_GetBitmapSample, what should I put as the width and height parameter?? Shouldn't it be flexible according to the imageview or the web image??
You will need to implement such a solution. You will need to find the correct ImageView and get its size. However you can also use an approximated size that will be good for all images.
You will need to implement such a solution. You will need to find the correct ImageView and get its size. However you can also use an approximated size that will be good for all images.
How should I modify the ImageDownloader to determine whether the same images have already been downloaded and reload the previously downloaded image so that the downloading won't repeat and waste the memory???
How should I modify the ImageDownloader to determine whether the same images have already been downloaded and reload the previously downloaded image so that the downloading won't repeat and waste the memory???
You'll have to create some kind of mechanism to remember what images you have downloaded. There isn't anyone made for you. It's not that hard to do, so just give it a try.
You'll have to create some kind of mechanism to remember what images you have downloaded. There isn't anyone made for you. It's not that hard to do, so just give it a try.
Let me put it this way.. For the ImageDownloader, anyone knows where the images are stored?? Is it in a temp file, a map or a list form?? Because I need to figure out how it works before I can try to modify it...
How should I modify the ImageDownloader to determine whether the same images have already been downloaded and reload the previously downloaded image so that the downloading won't repeat and waste the memory???