-3

I want my app to run only on landscape orientation, so I have added android:screenOrientation="landscape"in every activity in the manifest.

But surprisingly I'm getting so many crashes in Crashlytics and it's showing in the data that the crash occurs while the device is in a portrait mode (how come it's on a prorate mode).

the crash says

Caused by android.content.res.Resources$NotFoundException
Resource ID #0x7f0a001e
android.content.res.Resources.getValue (Resources.java:2327)
android.content.res.Resources.loadXmlResourceParser (Resources.java:3692)
android.content.res.Resources.getLayout (Resources.java:2143)
android.view.LayoutInflater.inflate (LayoutInflater.java:396)
android.view.LayoutInflater.inflate (LayoutInflater.java:354)
android.support.v7.app.AppCompatDelegateImplV9.setContentView (AppCompatDelegateImplV9.java:287)
android.support.v7.app.AppCompatActivity.setContentView (AppCompatActivity.java:139)
com.xx.xxx.Activity.onCreate (Activity.java:42)
android.app.Activity.performCreate (Activity.java:5447)
android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1094)
android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2393)
android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:2493)
android.app.ActivityThread.handleRelaunchActivity (ActivityThread.java:4014)
android.app.ActivityThread.access$900 (ActivityThread.java:166)
android.app.ActivityThread$H.handleMessage (ActivityThread.java:1289)
android.os.Handler.dispatchMessage (Handler.java:102)
android.os.Looper.loop (Looper.java:136)
android.app.ActivityThread.main (ActivityThread.java:5584)
java.lang.reflect.Method.invokeNative (Method.java)
java.lang.reflect.Method.invoke (Method.java:515)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:1268)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1084)
dalvik.system.NativeStart.main (NativeStart.java)

and this is my onCreate method @Override

   protected void onCreate(Bundle savedInstanceState) {
        setTheme(((AppTheme)getApplicationContext()).getCurrentTheme());
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_layout);
        ButterKnife.bind(this);
        presenter = new Presenter(this);
        setupPages();
        enterImmersiveMode();
    }

I'm wondering how it's recorded on Crashlytics that the crash occurs when the device is on portrait mode . so I guess that when it's on portrait mode it can't get the layout cuz all the layout in (layout-land) not in the layout folder.

Ran
  • 145
  • 2
  • 11
  • 3
    Possible duplicate of [how to force an Android app into landscape only or portrait only?](https://stackoverflow.com/questions/22668477/how-to-force-an-android-app-into-landscape-only-or-portrait-only) – LS_ Jul 02 '18 at 14:42
  • post the entire crash – letsCode Jul 02 '18 at 14:54
  • post your onCreate method. – letsCode Jul 02 '18 at 15:00
  • which of those lines are line 42? – letsCode Jul 02 '18 at 15:05
  • @DroiDev setContentView(R.layout.activity_layout); – Ran Jul 02 '18 at 15:07
  • does activity_layout exist? There could be an error within activity layout. the error means there is an issue with a resource (hence the R). – letsCode Jul 02 '18 at 15:11
  • Try cleaning the project, and rebuilding. – letsCode Jul 02 '18 at 15:11
  • hmm I don't think this will fix the problem, cuz it's working perfectly with me, but in the Crashlytics this is the crash I found, and it occurred many times, and when I dig deeper to see the crash data, I found it occurs when the app in portrait mode, so I'm wondering how it comes in portrait mode in the first place. – Ran Jul 02 '18 at 15:14

2 Answers2

1

I don't want to encourage laziness. Here is the answer.

However, please use Google next time. This is some basic information you can find easily.

Add android:screenOrientation="landscape" to the activity in the manifest.

    <activity android:name=".MainActivity"
        android:screenOrientation="landscape">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
letsCode
  • 2,774
  • 1
  • 13
  • 37
0

You can also change orientation on runtime with setRequestedOrientation(android.content.pm.ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); but you should call before setContentView

Thracian
  • 43,021
  • 16
  • 133
  • 222
  • it's set to landscape and working correctly with me, but I'm getting many crashes. I don't know why ! – Ran Jul 02 '18 at 15:06
  • It's quite strange indeed. If set in AndroidManifest.xml it should not change even if user rotates his/her device – Thracian Jul 02 '18 at 15:24