Each and everytime I use swipe option to swipe b/w Images I always get OutOfMemoryError
. Either I am using ViewPager
or ActivitySwipeDetector
every time this error occured. I am using android:largeHeap="true"
its work on API level 11 and above. But what to do if we are using minimum API level 8. And what guidelines we have to follow for elminating this error and working with lots of bitmaps?
Asked
Active
Viewed 82 times
0

John R
- 2,078
- 8
- 35
- 58
-
This question is as broad as the moon. Try these links: http://stackoverflow.com/questions/4544919/android-how-to-handle-out-of-memory-exception https://developer.android.com/training/displaying-bitmaps/manage-memory.html – VM4 Apr 01 '14 at 09:53
-
Check these - https://developer.android.com/training/displaying-bitmaps/manage-memory.html, http://developer.android.com/training/displaying-bitmaps/process-bitmap.html, http://developer.android.com/training/displaying-bitmaps/index.html – Kanak Sony Apr 01 '14 at 09:54
1 Answers
0
Here are a few suggestions to avoid OOM in ViewPager.
- If the bitmap sizes for the image views in your view pager are very big, then dynamically resize the bitmap based on the screen size.
- Call bitmap.recycle() in the destroyItem method of view pager adapter to free up memory (ginger bread devices). If you have not implemented destroyItem correctly, then it could lead to memory issues.
- Set setOffscreenPageLimit to a small value (say 2) to minimize the number of bitmaps.

Kiran Kumar
- 1,192
- 8
- 10