For the More Curious: Mipmap Images

Resource qualifiers and drawables are handy. When you need an image in your app, you generate the image in a few different sizes and add the versions to your resource-qualified folders: drawable-mdpi, drawable-hdpi, etc. Then you reference the image by name, and Android figures out which density to use based on the current device.

However, there is a downside to this system. The APK file that you release to the Google Play Store will contain all of the images in your drawable directories at each density that you added to your project – even though many of them will not be used. That is a lot of bloat.

To reduce this bloat, you can generate separate APKs for each screen density. You would have an mdpi APK of your app, an hdpi APK, and so on. (For more info on APK splitting, see the tools documentation at developer.android.com/​studio/​build/​configure-apk-splits.xhtml.)

But there is one exception. You want to maintain every density of your launcher icon.

A launcher on Android is a Home screen application (you will learn much more about launchers in Chapter 24). When you press the Home button on your device, you are taken to the launcher.

Some newer launchers display app icons at a larger size than launchers have traditionally displayed them. To make the larger icons look nice, these launchers will take an icon from the next density bucket up. For example, if your device is an hdpi device, the launcher will use the xhdpi icon to represent your app. But if the xhdpi version has been stripped from your APK, the launcher will have to fall back to the lower resolution version.

Scaled-up low-res icons look fuzzy. You want your icon to look crisp.

The mipmap directory is Android’s solution to this problem. When APK splitting is enabled, mipmaps are not pruned from the APKs. Otherwise, mipmaps are identical to drawables.

As of this writing, new projects in Android Studio are set up to use a mipmap resource for their launcher icon (Figure 23.6).

Figure 23.6  Mipmap icons

Screenshot shows Mipmap icons. The Nested menu shows mipmap icons in res menu.

We recommend putting just your launcher icon in the various mipmap directories. All other images belong in the drawable directories.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.117.183.172