Since Android 4.3 (Jelly Bean) we can now make use of the res/mipmap
folders to store "mipmap" images.
For example, Chrome for Android stores its icons in these folders instead of the more normal res/drawable
folders.
How are these mipmap images different from the other familiar drawable images?
I see that in my manifest, we use the @mipmap/
qualifier, instead of @drawable/
, which makes sense given the resource folder name:
<activity
android:name=".MipmapDemp"
android:icon="@mipmap/ic_launcher" />
References:
The Android 4.3 APIs document has the following to say:
Using a mipmap as the source for your bitmap or drawable is a simple way to provide a quality image and various image scales, which can be particularly useful if you expect your image to be scaled during an animation.
Android 4.2 (API level 17) added support for mipmaps in the Bitmap class—Android swaps the mip images in your Bitmap when you've supplied a mipmap source and have enabled setHasMipMap(). Now in Android 4.3, you can enable mipmaps for a BitmapDrawable object as well, by providing a mipmap asset and setting the android:mipMap attribute in a bitmap resource file or by calling hasMipMap().
I don't see anything in there that helps me to understand.
XML Bitmap resources have an android:mipMap
property:
Boolean. Enables or disables the mipmap hint. See setHasMipMap() for more information. Default value is false.
This does not apply to launcher icons as far as I can see.
The question was raised on Google Groups (The purpose of resource name "mipmap"?!), to which Romain Guy replied:
It's useful to provide an image at a larger resolution that would normally be computed (for instance, on an mdpi device, Launcher might want the larger hdpi icon to display large app shortcuts.)
I feel like this almost makes sense of it, but not quite.
I'm still inclined to go with Randy Sugianto's follow up:
What are the advantages of this? Is there any guide how to use mipmaps, probably for better launcher icons?
Of course, Wikipedia has a page for "Mipmap", which refers to an older technique invented in 1983, that I can't quite relate to the current Android implementation.
Should we be storing all our app icons in res/mipmap
folders these days, and what are the guidelines for these mipmap images?
Update #1
Here's a blog post that tries to explain it a bit.
But the image used in that blog post shows what looks like one file with many logos in it. This is not what I see in Chrome's mipmap folder.
Chrome's mipmap-hdpi
folder contains three images. One is the Chrome logo, on its own.
Strangely, it is 72x72, not 48x48 which I would expect to see.
Perhaps that is all there is to this - we just need to keep bigger icons in the mipmap folders?
Update #2
The Android Developers Blog post of 23/10/2014 again confirms the idea of using the mipmap
folders for application icons:
When talking about the Nexus 6 screen density, the author writes:
It’s best practice to place your app icons in mipmap- folders (not the drawable- folders) because they are used at resolutions different from the device’s current density. For example, an xxxhdpi app icon can be used on the launcher for an xxhdpi device.
Update #3
Note that Android Studio creates the ic_launcher.png
icons in the mipmap...
folders rather than the drawable...
folders that Eclipse used to create them in.
Since I was looking for an clarifying answer to this to determine the right type for notification icons, I'd like to add this clear statement to the topic. It's from http://developer.android.com/tools/help/image-asset-studio.html#saving
If you build an APK for a target screen resolution like HDPI, the Android asset packageing tool,AAPT,can strip out the drawables for other resolution you don’t need.But if it’s in the mipmap folder,then these assets will stay in the APK, regardless of the target resolution.
The understanding I have about mipmap is more or less like this:
When an image needs to be drawn, given we have different screen sizes are resolutions, some scaling will have to take part.
If you have an image that is ok for a low end cell phone, when you scale it to the size of a 10" tablet you have to "invent" pixels that don't actually exist. This is done with some interpolation algorithm. The more amount of pixels that have to be invented, the longer the process takes and quality starts to fail. Best quality is obtained with more complex algorithms that take longer (average of surrounding pixles vs copy the nearest pixel for example).
To reduce the number of pixels that have to be invented, with mipmap you provide different sizes/rsolutions of the same image, and the system will choose the nearest image to the resolution that has to be rendered and do the scaling from there. This should reduce the number of invented pixels saving resources to be used in calculating these pixels to provide a good quality image.
I read about this in an article explaining a performance problem in libgdx when scaling images:
http://www.badlogicgames.com/wordpress/?p=1403
MipMap for app icon for launcher
http://android-developers.blogspot.co.uk/2014/10/getting-your-apps-ready-for-nexus-6-and.html
https://androidbycode.wordpress.com/2015/02/14/goodbye-launcher-drawables-hello-mipmaps/
When building separate apks for different densities, drawable folders for other densities get stripped. This will make the icons appear blurry in devices that use launcher icons of higher density. Since, mipmap folders do not get stripped, it’s always best to use them for including the launcher icons.