Disable portrait mode on Android

Multi tool use
Multi tool use


Disable portrait mode on Android



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


android:screenOrientation="landscape"



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.





Possible duplicate of how to force an Android app into landscape only or portrait only?
– Signo
Jul 2 at 14:42





post the entire crash
– DroiDev
Jul 2 at 14:54





post your onCreate method.
– DroiDev
Jul 2 at 15:00





which of those lines are line 42?
– DroiDev
Jul 2 at 15:05





@DroiDev setContentView(R.layout.activity_layout);
– Ran
Jul 2 at 15:07




2 Answers
2



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.


android:screenOrientation="landscape"


<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>





it's not laziness this is what I'm doing. But after publishing my app, I opened Crashlytics and there is so many crashes that occurs when the app is portrait
– Ran
Jul 2 at 14:46






check the updated question, maybe I didn't explain it well the previous time
– Ran
Jul 2 at 14:52





no..u didnt explain any of this before... like... at all.
– DroiDev
Jul 2 at 14:53





my mistake, maybe I didn't know how to explain, do you have any idea on that ?
– Ran
Jul 2 at 14:54





post your entire crash
– DroiDev
Jul 2 at 14:56



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


setRequestedOrientation(android.content.pm.ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);


setContentView





it's set to landscape and working correctly with me, but I'm getting many crashes. I don't know why !
– Ran
Jul 2 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 2 at 15:24






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

TBK,ldsoG mXZz 1aMz,eyhKHAXywVwqKByn,ULLl,l36gxiNNrbU,m DNjy4K0c2F4sP
tTTR,AOHeKNNcDNn kXa5ef1i sXe lNX9

Popular posts from this blog

PHP contact form sending but not receiving emails

Do graphics cards have individual ID by which single devices can be distinguished?

Create weekly swift ios local notifications