Search code examples
androidandroid-layoutandroid-manifestandroid-orientation

Activity screen orientation issue


My Activity only supports landscape mode by specifying

android:screenOrientation="sensorLandscape" 

in manifest.

Now if my Activity is in foreground and some other app, which supports both orientation, gets launched and user changes orientation to portrait and hits back then my Activity gets crashed throwing:

android.content.res.Resources$NotFoundException

I guess it looks for layout resources for portrait mode briefly and layouts are only in layout-land so it get crashed.

E.g. I launch my app, lock the screen, rotate device to portrait mode, unlock device and I can see crash and ANR.

Any idea how to resolve this issue?


Solution

  • Copy your layouts to the portrait directories (res/layout), in this brief moment when the system tries to render your layout then it won't crash from a resource not found exception