What is the res directory and how do you use orientation qualifiers?

Android's declarative resource system and runtime configuration adaptation.
res/ holds non-code assets; create layout-port/ and layout-land/ with identical XML filenames for automatic framework selection.
What's really being asked
This question probes two foundational Android concepts: the resource system and configuration qualifiers. The interviewer wants to know if you trust the framework to handle device variations declaratively rather than writing manual branching code. Seniors should demonstrate awareness that res/ is not just a folder but a runtime resolution engine that maps device state to the correct asset without explicit code intervention.
The full answer
First, state that the res/ directory contains non-code resources such as layouts, strings, colors, drawables, dimensions, and raw files. These are compiled into the R class and accessed via generated integer IDs. Second, explain that resource qualifiers are directory name suffixes that let the framework choose the best match for the current device configuration. For portrait and landscape, you create res/layout-port/ and res/layout-land/ directories. Third, emphasize that the XML files inside must share identical filenames so that R.layout.main resolves to the correct variant automatically. Fourth, note that this works because a configuration change triggers the framework to reload resources, and if the Activity does not handle configChanges manually in the manifest, it recreates and pulls the new layout.
The mistakes people make
A major red flag is saying you would detect orientation in onCreate using getResources().getConfiguration().orientation and then inflate different layouts manually. Another red flag is using different filenames like main_port.xml and main_land.xml, which breaks the qualifier abstraction and forces conditional logic in code. Claiming that res/ is only for images, confusing res/ with assets/, or stating that qualifiers require programmatic registration are also serious gaps that reveal a lack of production experience.
What usually comes next
The interviewer may ask what happens when you add android:configChanges="orientation" to the manifest, which prevents Activity recreation and therefore skips automatic resource reloading. They might also ask how to handle orientation for Fragments, or how the framework resolves conflicts when multiple qualifiers match, such as layout-sw600dp-land versus layout-land. A senior candidate should mention that the framework picks the most specific match and falls back to the default if no exact qualifier directory exists.
A concrete example
Suppose you have a news detail screen. In res/layout/ you place article_detail.xml with a single column for phones in portrait. In res/layout-land/ you place another article_detail.xml that uses a two-pane layout with the image on the left and text on the right. When the user rotates the device, the Activity is recreated and setContentView(R.layout.article_detail) automatically inflates the landscape version without any conditional code. This declarative approach keeps the Activity free of orientation branching and lets the system handle caching and inflation efficiently.
Interview question
What is required for Android to automatically select a landscape layout when the device rotates, without adding orientation logic in your Activity?
- a.Create res/layout-land/ and place an XML file with the identical filename used in res/layout/Correct
- b.Add android:configChanges="orientation" to the manifest and call setContentView in onConfigurationChanged
- c.Create res/layout-land/ with a differently named XML file and reference it via getResources().getConfiguration().orientation
- d.Put the landscape XML in res/assets/layout-land/ and inflate it using AssetManager
Why? this is the answer
The framework matches the current configuration to qualifier directories at runtime, but only when XML files share the same name so R.layout.name resolves to the correct variant automatically. Detecting orientation manually or using configChanges prevents this automatic declarative selection and forces unnecessary branching code.
Just read this? Test yourself on what you have been reading.
Read the original → developer.android.com
You just looked this up. Could you explain it out loud?
That is the part interviews actually test. Tezvyn takes questions like this one and gives you what the interviewer is really checking, the answer that lands, and the mistake that ends the conversation, in the four minutes before your next meeting.
The iPhone app is on the way
We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.
Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.
We are hiring for this. Open roles that interview on android — each one lists the topics its interview covers.
See open roles