1

I have a fragment contains 6 ViewFlippers, each flipper contains at least 10 ImageViews. I tried to load all the images and put them in the ImageViews but the restricted memory didn't let me to do that. Every time I run the application this exception occurs.

when I reduce number of images my app runs, but that's not a solution.
So what's the best way for doing that?

Here what I tried so far:

for(int i=0; i<flippers.length; i++) {
    for (int j = 0; j < names.length; j++) {
        int imageResource = getResources().getIdentifier(names[j], "drawable", rootView.getContext().getPackageName());
        ImageView imageView = new ImageView(rootView.getContext());
        imageView.setImageResource(imageResource);
        flippers[i].addView(imageView);
    }
}

26546-26546/com.azad E/AndroidRuntime﹕ FATAL EXCEPTION: main Process: com.azad, PID: 26546 java.lang.OutOfMemoryError

3
  • 1
    Did u check this link? Commented Mar 1, 2015 at 15:11
  • 1
    I think you could use some libraries which have image caching and resizing image before using it to reduce memory usage. There are many, the Android Universal Image Loader library could be a good choice for you. Commented Mar 1, 2015 at 15:15
  • 1
    you need to reduce image size(pixels), for example an Image with 1080*3000 px with "70 Kb size" , get about "50 Mb" of ram Commented Mar 1, 2015 at 15:18

1 Answer 1

1

Make use of library for resizing the image before loading

Some of the library you can use are

Picasso

UIL

This library will help you to cache the image. And when the image is not required you can clear it from memory

Sign up to request clarification or add additional context in comments.

2 Comments

+1, I used Picasso, it will only load most of the images. Now I have two ViewFlippers with empty imageViews. Why is that? Is it because of memory ?
Are you using .resize() method of Picasso while loading image?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.