Google I/O 2012 - Doing More With Less: Being a Good Android Citizen
Why Stack Overflow recommends it
Stack Overflow users link it when answering Android memory questions such as OutOfMemoryError, bitmap handling and LruCache design, citing it as advice straight from the platform team.
Recommended by 11 people across 10 different months, 2012 to 2014.
What it is
A Google I/O 2012 talk by Jeff Sharkey on making Android apps lighter and faster. It covers CPU, RAM and I/O efficiency, memory management, bitmap caching with LruCache, onTrimMemory callbacks, and best practices for JNI and SQLite.
What people said
Strong rec A Random Android Dev · 2012-08 · Stack Overflow · on “GC messages in Android”
Those three lines are messages from the Garbage Collector (GC) read this article on Garbage Collection [LINK] and the sizes (i.e 1669K, 53715K) are the sizes of memory freed by collecting and destroying objects that occupied that much RAM memory. Out Of Memory Error (OOM) is, in simple terms, the OS telling you that your application is consuming more memory than is allocated to it and that you should do something about it. Now, in order to remove the OOM and for best practices please watch this excellent video about memory-management and best practices: Google I/O 2012 - Doing More With Less [this video] .
Recommends Budius · 2012-08 · Stack Overflow · on “Android OutOfMemory within different devices ?”
Caused by: java.lang.OutOfMemoryError: bitmap size exceeds VM budget that line says it all. The bitmaps are hogging all the memory of some devices (devices that the VM stack limit is higher). You should look into better memory management for this application such as LruCache, decode bitmaps with lower quality, etc. edit: do not use WeakReference as some users might suggest. check this question Does Android need to load a complete Bitmap from a file before sampling it down? [LINK] and also this video [this video] direct explanations/teachings/techniques from the creators of the platform and say to not use WeakReference.
Recommends Budius · 2012-08 · Stack Overflow · on “Does Android need to load a complete Bitmap from a file before sampling it down?”
Newer versions might have more physical memory but it's still limited to whatever is the system stack size; that way, programming bitmap still should be done very carefully with the amount of memory used. On this years Google I/O (2012) there was a great presentation named "Doing more with less" that shows some very nice caching techniques you should look into. I'm sure you can find this video on YouTube Android Developers account. Found the video: [this video]
Recommends Budius · 2012-08 · Stack Overflow · on “Does Android need to load a complete Bitmap from a file before sampling it down?”
Do not use WeakReference! One of the advice/tecnique on the video I mentioned is that WeakReference are not very good for that, even thou largely used. It points and shows code to use LruCache instead that is available in the Compatibility pack the video is here: [this video]
Recommends Ian Warwick · 2012-09 · Stack Overflow · on “Android, retrieve thumbnail by parsing URL as argument using SimpleCursorAdapter.ViewBinder”
I can show you a way that I have used and it worked quite well, first off we need a way to cache the images and the best way I have seen to date, is to use the LruCache as described in the excellent Google IO presentation doing more with less: [this video] Here is my implementation of the method described in that presentation. public class BitmapCache extends LruCache<String, Bitmap> { public BitmapCache(int sizeInBytes) { super(sizeInBytes); } public BitmapCache(Context context) { super(getOptimalCacheSizeInBytes(context)); } public static int getOptimalCacheSizeInBytes(Context context) { ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); int memoryClassBy
Recommends Marius Kjeldahl · 2012-09 · Stack Overflow · on “Fast per-pixel blend effect "multiply" in C# (for android)”
If you want fast, you need to look into Renderscript, [LINK] . This video from Google also shows you more or less everything you need, [this video] (Google IO 2012 - Doing More With Less: Being a Good Android Citizen).
Recommends Budius · 2012-10 · Stack Overflow · on “Cache small bitmaps from database”
Absolutely no. The LruCache is the proper approach to cache stuff, it doesn't matter the size of the images. Remember to create the cache as a singleton element to be accessed equally by any element on your whole application. DO NOT USE WeakReference as some people will suggest. They do not work very well on the Android, if you're in a search mood you can check the Google IO 2012 talks on YouTube that the Android team themselves are explaining why not use WeakReference and how to properly use LruCache. edit found the youtube link [this video]
Recommends Sandra · 2012-10 · Stack Overflow · on “android onTrimMemory and ComponentCallbacks2”
Listening to the "Google I/O 2012 - Doing More With Less: Being a Good Android Citizen" talk, which you can see here [this video] i found out that since api level 14 you can override onTrimMemory if you like to do some things like reducing the memory usage. But I want to implement the ComponentCallbacks2 interface outside my Activity, in my CursorAdapter for instance. In this talk it says: use Context.registerComponentCallbacks() , but when I try to use this it requires an input parameter, like this mContext.registerComponentCallbacks(ComponentCallbacks callbacks); How can I use this? Now I am using this public class ContactItemAdapter extends ResourceCursorAdapter implements ComponentCallbacks2{
Recommends Taras Leskiv · 2012-12 · Stack Overflow · on “Handling Large Bitmaps in Image Editor”
Have a look at this video from Google I/O [this video] where they develop an Advanced gallery app with image editing. You can download source code for the application here [LINK] . This is how it opens the activity for image editing: private OnItemClickListener mPhotoClickListener = new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // User clicked on photo, open our viewer final Intent intent = new Intent(AlbumActivity.this, PhotoActivity.class); final Uri data = ContentUris.withAppendedId( MediaStore.Images.Media.EXTERNAL_CONTENT_URI, id); intent.setData(data); startActivity(intent); } }; The gallery also implements image edi
Recommends Taras Leskiv · 2013-01 · Stack Overflow · on “Listview items remove bitmaps from memory when the user scrolls”
You should consider looking at Sample Gallery App from Google I/O 2012. Everything you need is implemented there. Video from Google I/O about gallery app [this video] Source code is available on Google Code [LINK] and it's an exclellent example of building a Gallery. You should also consider looking at Romain Guy's presentation [LINK] (beginning) where he explains performance issues with ListView and teaches to use adapters efficiently. (ViewHolder pattern and reusing views). Here's a RecycleListener for GridView (Available from API level 1). A RecyclerListener is used to receive a notification whenever a View is placed inside the RecycleBin's scrap heap. This listener is used to free resources a