[Solved] My application crashes when i load huge amount of bitmaps in arraylist


If all of your images are similarly sized, you are attempting to allocate ~2028601104 bytes = ~1981055KB = ~1934MB. You have 64MB or less on most Android devices that your app can use.

The image that you failed on is 22050012 bytes in size, when decoded and perhaps scaled. That is equivalent to 2347 x 2347 pixels. Few if any Android devices have screens of that resolution.

So, you need to do several things:

  1. Stop trying to load all of the bitmaps up front. Load them as needed.

  2. Reduce the resolution of the bitmaps.

  3. If you put the bitmaps in any directory other than res/drawable-nodpi/, move them to res/drawable-nodpi/. For example, if you put them in res/drawable/, that is a synonym for res/drawable-mdpi/, indicating that the images are designed for mdpi devices (~160dpi). Android will automatically scale those images up for higher-density devices. If you have images that are large, you cannot afford for Android to do that sort of scaling. res/drawable-nodpi/ tells Android that these images are not tied to a particular density and so should not be scaled this way.

You might also want to reconsider this entire plan. Working with lots of bitmaps — let alone large ones — is complicated even for experienced Android app developers. Memory management is hard. If you are new to Android, perhaps you should consider a project that will be simpler to implement.

0

solved My application crashes when i load huge amount of bitmaps in arraylist