In my app we are using a gallery for photos , taken from android dev (http://developer.android.com/resources/tutorials/views/hello-gallery.html) .It loads all the photos from /sdcard/DCIM (all subdirectories). Althought we have made it resample the shown image to use less memory, it still crashes if the users has a lot of pictures or scrolls too fast.
Are there any suggestions on how to make gallery not crash the application??
(Shouldn't google have provided us with a gallery "out of the self" that takes care of all these issues?)
The problem with the standard android gallery is that it will not use view recycling. You can do whatever you want cache images etc. The gallery itself will keep all imageviews that are added to the gallery in memory. This may lead to a fast scrolling gallery, but it also leads to a lot of out of memory exceptions.
A good solution for this is to use the Compatibility Library (available since Api Level 4) and the Viewpager that can be found in there. It will give you a very maintainable gallery that is much more usable (no more jumping of images etc.) and if you are using a FragemtSatePagerAdapter the fragments that are not currently shown in the gallery may be destroyed, if memory gets tight.
Be sure to implement the lifecycle of the fragments correct. This means:
If you are not using fragments yet using the viewpager may look like a lot of work. But it is worth it. You and your user will have a much nicer app afterwards.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With