Q:

Android looks for layout instead of layout-large when Activity is started for the second time

I want to provide different layouts depending on whether the app runs on a smartphone or on a tablet. Therefore I put different layout definitions in layout-normal resp. layout-large. 
During testing on tablet I run into a the following exception when the associated activity is started for the second time:
09-06 13:28:43.640: E/AndroidRuntime(26260): Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f030005
09-06 13:28:43.640: E/AndroidRuntime(26260):    at android.content.res.Resources.getValue(Resources.java:1010)
09-06 13:28:43.640: E/AndroidRuntime(26260):    at android.content.res.Resources.loadXmlResourceParser(Resources.java:2088)
09-06 13:28:43.640: E/AndroidRuntime(26260):    at android.content.res.Resources.getLayout(Resources.java:849)
09-06 13:28:43.640: E/AndroidRuntime(26260):    at android.view.LayoutInflater.inflate(LayoutInflater.java:389)
09-06 13:28:43.640: E/AndroidRuntime(26260):    at android.view.LayoutInflater.inflate(LayoutInflater.java:347)
09-06 13:28:43.640: E/AndroidRuntime(26260):    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:245)
09-06 13:28:43.640: E/AndroidRuntime(26260):    at android.app.Activity.setContentView(Activity.java:1786)
09-06 13:28:43.640: E/AndroidRuntime(26260):    ... 11 more

When the Activity is started for the first time everything is fine and the layout is inflated correctly. The error only occurs after the Activity has been finished and gets restarted from the previous Activity on the back stack.
I could reproduce the problem on Samsung Galaxy Tab running Android 3.2 and in the emulator for Android 3.2 and 4.1. The layout is loaded via Activity.setContentView(int resId), so there is no magic at this point. Furthermore the resource ID that gets logged in the stacktrace (#0x7f030005) corresponds to the id of the root layout in R.layout that is given to Activity.setContentView(int resId).
If I copy the layout from the layout-large to the layout folder and change the background color in the copy the exception is not thrown but the unspecific version from layout with the modified background color is loaded.
In the Manifest I already configured the supported screens
<supports-screens
    android:smallScreens="false"
    android:normalScreens="true" 
    android:largeScreens="true"
    android:xlargeScreens="true"
    android:anyDensity="true" />

Does anybody have an idea of how to fix this?

A:

The origin of the error was in an external library I used:
They were constructing an object subclassed from android.content.res.Resources to fake an in-memory resource. The Resources object's construction required an AssetManager as one of the parameters, which has been obtained using the Activity's getAssets() method. It seems that this was corrupting the resources.
It seems that the correct way to construct a Resource object is by passing in a brand new AssetManager instance (which also means using the private AssetManager constructor).

