0

I am developing a game having a scroll view which contains image buttons(Images in drawable are being used not from server), I got Out Of Memory error and to deal with OOM error I referred this answer,in which the image was scaled down to reduce memory but this is reducing my image quality to a great extent,

So my question is, How to solve OOM issue for Android App without reducing the image quality?

ZaidRehman
  • 1,631
  • 2
  • 19
  • 30
  • Completely random guess (not an Android person): load the images lazily as they scroll into view? Maybe buffer one screenful above and below the current view? Recent versions of Firefox (on desktop) do something similar to save memory on pages with lots of images. If you want better help, you should post a minimal code example so we can suggest modifications. – Jeffrey Bosboom Mar 06 '16 at 07:44

2 Answers2

1

Use library to load images in your application. Like Picaso or Glide

Also read difference between them here

I hope this will solve your problem.

Nitin Mali
  • 226
  • 1
  • 7
1

If you have many entities to show in a list, it is the best practice to use RecyclerView class.

RecyclerView's adapter class: RecyclerView.Adapter is using ViewHolder pattern which is re-cycling the not visible views when user scrolls the list. This is a way to avoid OOM and a very common method in Android development.

Example here.

Other way to use "plain old" ListView with your own written adapters, but in that way you have to implement ViewHolder pattern on your own. Btw there are plenty tutorials on the internet.

ScrollView is more likely a View for showing constant number of entities, more like the content of your application than showing many data instances. It is the main View for making a screen scrollable, but not "browsable". I hope my explanation is clear on this point.

And about the images: If you download the images and they are not simple drawable resources you can use some image downloader class which is using caching. A good solution would be: Picasso.

Adam Varhegyi
  • 11,307
  • 33
  • 124
  • 222