Getting out
This question already has an answer here:
Can get a scaled bitmap or try other options like inSampleSize
, do check how your solution affects the quality of your image too.
Esp for "..loading ALL the images at once, even the ones that aren't seen on the first tab.."(i have done the following for a similar implementation):
you can use inSampleSize
to load all images and replace the visible tab images by the original ones- meaning for the selected tab, dynamically load images without the inSampleSize
for the BitmapFactory
and its Options
.
You could scale them down depending on different devices to load the images without facing a memory problem. In your case, some phones may not exhibit the same behavior on the first run, but eventually, without handling an optimized image loading solution, app will crash.
Check more on this:
Topic under Load a Scaled Down Version into Memory.
http://developer.android.com/training/displaying-bitmaps/load-bitmap.html
Out of memory error on Android
On how to avoid them:
How to avoid an out of memory error while using bitmaps in Android
For an overview:
http://blogs.innovationm.com/android-out-of-memory-error-causes-solution-and-best-practices/ http://android-developers.blogspot.de/2009/01/avoiding-memory-leaks.html
Also, android:largeHeap
android:largeHeap="true" convention?
Well, there are so many ways to solve this proble, the fisrt one and better for me it's using a "Cache image loader", here it's a library created by Sergey Tarasevich, it's very useful.
https://github.com/nostra13/Android-Universal-Image-Loader
If you prefer to keep working like you're doing now, a simple but ugly solution it's to call:
System.gc() in order to indicate to system that you want to make a garbage collect (which will clean up some memory).
链接地址: http://www.djcxy.com/p/93106.html上一篇: drawable.setCallback的后果(null);
下一篇: 正在出去