The following is the first few sections of a chapter from The Busy Coder's Guide to Android Development, plus headings for the remaining major sections, to give you an idea about the content of the chapter.


Resource Sets and Configurations

Devices sometimes change while users are using them, in ways that our application will care about:

In all of these cases, it is likely that we will want to change what resources we use. For example, our layout for a portrait screen may be too tall to use in landscape mode, so we would want to substitute in some other layout.

This chapter will explore how to provide alternative resources for these different scenarios — called “configuration changes” — and will explain what happens to our activities when the user changes the configuration while we are in the foreground.

What’s a Configuration? And How Do They Change?

Different pieces of Android hardware can have different capabilities, such as:

Some of these, in the eyes of the core Android team, might drive the selection of resources, like layouts or drawables. Different screen sizes might drive the choice of layout. Different screen densities might drive the choice of drawable (using a higher-resolution image on a higher-density device). These are considered part of the device’s “configuration”.

Other differences — ones that do not drive the selection of resources — are not part of the device’s configuration but merely are “features” that some devices have and other devices do not. For example, cameras and Bluetooth and WiFi are features.

Some parts of a configuration will only vary based on different devices. A screen will not change density on the fly, for example. But some parts of a configuration can be changed during operation of the device, such as orientation (portrait vs. landscape) or language. When a configuration switches to something else, that is a “configuration change”, and Android provides special support for such events to help developers adjust their applications to match the new configuration.

Configurations and Resource Sets

The preview of this section is in the process of being translated from its native Klingon.

Screen Size and Orientation

The preview of this section is unavailable right now, but if you leave your name and number at the sound of the tone, it might get back to you (BEEEEEEEEEEEEP!).

Coping with Complexity

The preview of this section was accidentally identified as an Android 'tasty treat' by the Cookie Monster.

Choosing The Right Resource

The preview of this section was stepped on by Godzilla.

API-Versioned Resources

The preview of this section is sleeping in.

Default Change Behavior

The preview of this section is unavailable right now, but if you leave your name and number at the sound of the tone, it might get back to you (BEEEEEEEEEEEEP!).

State Saving Scenarios

The preview of this section is in the process of being translated from its native Klingon.

Your Options for Configuration Changes

The preview of this section is presently indisposed.

Blocking Rotations

The preview of this section is being chased by zombies.

And Now, a Word From the Android Project View

The preview of this section did not survive Thanos's finger snap.

Configuration Challenges

The preview of this section is in an invisible, microscopic font.