Android searches for a resource in the portrait folder, even if the application is locked in Landscape

I ran into a strange problem. My application is locked on the landscape. My app is a tablet app supporting 7 inches ahead. So I created two folders under the res folder - layout-sw600dp-land and layout-sw720dp-land, and I put all my layout resources under it. It looks great when the screen rotates, works as expected. But when I turn my screen and press the home button, the android looks in the portrait folder for resource and application failures, because there is no resource in the portrait folder. Why does android look in the portrait folder even when I mentioned in the manifest that the orientation of the application is landscape. See my code below. Am I doing something wrong?

   android:name="com.example.activities.fragmentActivity"
    android:configChanges="keyboardHidden|orientation|screenSize"
    android:screenOrientation="sensorLandscape" >
</activity>

The structure of my folder is as follows:

res
layout
layout-sw600dp-land
layout-sw720dp-land

When I put my resources in the layout folder, this will prevent a crash. Therefore, it is clear that Android is looking for a folder with a portrait of resources. Can anyone help me solve this problem.

Stacktrace

07-24 16:40:00.383: E/AndroidRuntime(16041): FATAL EXCEPTION: main
07-24 16:40:00.383: E/AndroidRuntime(16041): Process: com.sample.android, PID: 16041
07-24 16:40:00.383: E/AndroidRuntime(16041): android.content.res.Resources$NotFoundException: Resource ID #0x7f030003
07-24 16:40:00.383: E/AndroidRuntime(16041):    at android.content.res.Resources.getValue(Resources.java:1123)
07-24 16:40:00.383: E/AndroidRuntime(16041):    at android.content.res.Resources.loadXmlResourceParser(Resources.java:2309)
07-24 16:40:00.383: E/AndroidRuntime(16041):    at android.content.res.Resources.getLayout(Resources.java:939)
07-24 16:40:00.383: E/AndroidRuntime(16041):    at android.view.LayoutInflater.inflate(LayoutInflater.java:395)
07-24 16:40:00.383: E/AndroidRuntime(16041):    at com.sample.android.fragments.sampleFragment.onCreateView(sampleFragment.java:189)
07-24 16:40:00.383: E/AndroidRuntime(16041):    at android.support.v4.app.Fragment.performCreateView(Fragment.java:1478)
07-24 16:40:00.383: E/AndroidRuntime(16041):    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:927)
07-24 16:40:00.383: E/AndroidRuntime(16041):    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1104)
07-24 16:40:00.383: E/AndroidRuntime(16041):    at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
07-24 16:40:00.383: E/AndroidRuntime(16041):    at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1460)
07-24 16:40:00.383: E/AndroidRuntime(16041):    at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:440)
07-24 16:40:00.383: E/AndroidRuntime(16041):    at android.os.Handler.handleCallback(Handler.java:733)
07-24 16:40:00.383: E/AndroidRuntime(16041):    at android.os.Handler.dispatchMessage(Handler.java:95)
07-24 16:40:00.383: E/AndroidRuntime(16041):    at android.os.Looper.loop(Looper.java:136)
07-24 16:40:00.383: E/AndroidRuntime(16041):    at android.app.ActivityThread.main(ActivityThread.java:5001)
07-24 16:40:00.383: E/AndroidRuntime(16041):    at java.lang.reflect.Method.invokeNative(Native Method)
07-24 16:40:00.383: E/AndroidRuntime(16041):    at java.lang.reflect.Method.invoke(Method.java:515)
07-24 16:40:00.383: E/AndroidRuntime(16041):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
07-24 16:40:00.383: E/AndroidRuntime(16041):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
07-24 16:40:00.383: E/AndroidRuntime(16041):    at dalvik.system.NativeStart.main(Native Method)
+4
source share
8 answers

I do not believe that placing layouts (or any other resource) in an override directory without an appropriate layout is supported by default. Of course, lint complains if you put a string in a directory values-lland there is valuesno corresponding string in it.

My advice: move content layout-sw600dp-landto layout.

You limit supported devices in other ways, right?

+1
source

configChanges.

0

: screenOrientation = "" ..

0

, -sw600dp-land

0

, Android .

, , - . , .

, :

layout (default = what you used to have in sw600dp-land)
layout-sw720dp (remove -land, not needed since you locked in landscape)

- , -sw600dp .

0

configChanges , onConfigurationChanged if, , .

, :

@Override
    public void onConfigurationChanged(Configuration newConfig) {

        if (myActivity.isLandscape()) {


        }
   }

.

0

, .

- , , onConfigurationChange. , , .

: ,

android:screenOrientation="sensorLandscape"

to

android:screenOrientation="landscape"

:

android:configChanges="keyboardHidden|orientation|screenSize"

And check it out.

If, however, it crashes, let me know, I will check the depth in your problem and try to solve it.

0
source

screenOrientationapplies only when your activity is ahead. Android expects your activity to be able to exist in the background without glitches, even if the device is in a different orientation. Like everyone else, do not use unnecessary resource qualifiers.

0
source

Source: https://habr.com/ru/post/1548441/


All Articles