0

Sorry if this sound newb but.. =[

Im working with an application which need to load a large amount of images onto a textview, i didnt use webview becuz sometimes it doesnt lead to mobile view so i decide to parse the content and use html.fromHtml to show it to the Textview.

Problem is: if i load a page is luckily there not much images, it run pretty smooth. otherwise it get the error like below...

anyone know if theres a way that i can dispose the source from the system memory after it finished reading the image?...or...any other way will fix my problem?

i used the source from here Android ImageGetter images overlapping text

    05-08 21:30:31.404: ERROR/dalvikvm-heap(25083): Out of memory on a 1920016-byte allocation.
    05-08 21:30:31.404: ERROR/AndroidRuntime(25083): FATAL EXCEPTION: AsyncTask #10
    java.lang.RuntimeException: An error occured while executing doInBackground()
    at android.os.AsyncTask$3.done(AsyncTask.java:299)
    at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
    at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
    at java.util.concurrent.FutureTask.run(FutureTask.java:137)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
    at java.lang.Thread.run(Thread.java:856)
    Caused by: java.lang.OutOfMemoryError
    at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
    at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:527)
    at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:353)
    at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:781)
    at android.graphics.drawable.Drawable.createFromStream(Drawable.java:741)
    at com.vilalab.five.model.URLImageParser$ImageGetterAsyncTask.fetchDrawable(URLImageParser.java:90)
    at com.vilalab.five.model.URLImageParser$ImageGetterAsyncTask.doInBackground(URLImageParser.java:58)
    at com.vilalab.five.model.URLImageParser$ImageGetterAsyncTask.doInBackground(URLImageParser.java:48)
    at android.os.AsyncTask$2.call(AsyncTask.java:287)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
    ... 4 more
   05-08 21:30:31.504: ERROR/dalvikvm-heap(25083): Out of memory on a 1920016-byte allocation.
Community
  • 1
  • 1
zBaoAnhLe
  • 253
  • 1
  • 6
  • 19
  • out of memory occurs coz you are exceeding the haep size allocated for your app. scale down the image.http://developer.android.com/training/displaying-bitmaps/load-bitmap.html – Raghunandan May 08 '13 at 14:50
  • If you have an image url(web url), you can use cache technique. – Kanth May 08 '13 at 15:50
  • i used this code to show the image in my textview http://stackoverflow.com/questions/7870312/android-imagegetter-images-overlapping-text/10208504#10208504 – zBaoAnhLe May 08 '13 at 15:58

1 Answers1

0

Check out this post, it uses the example of getting picutres from the SD Card/Gallery for how to downsample images so that you avoid this problem. Its a pretty easy fix.

Community
  • 1
  • 1
Rarw
  • 7,645
  • 3
  • 28
  • 46
  • isnt this only work if the image is already in ur sd card tho?...=( my apps i get the url of the image and use drawable to draw it..i have not see much ppl give a specific solution for this :(. – zBaoAnhLe May 08 '13 at 15:09
  • Well that example is in the context of an image from the SD card. But based on the log you are using BitmapFactory to decode the input stream. It is very easy to impliment the suggested code in that post into your processing of the image stream. – Rarw May 08 '13 at 16:26