How do I set it so the application is running in portrait mode only? I want the landscape mode to be disabled while the application is running. How do I do it programmatically?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
For any Android version
From XML
You can specify
android:screenOrientation="portrait"for each activity in your manifest.xml file. You cannot specify this option on theapplicationtag.From Java
Other option is to do it programmatically, for example in an
Activitybase class:For Android 4+ (API 14+)
Last option is to do it with activity lifecycle listeners which is only available since Android 4.0 (API 14+). Everything happens in a custom
Applicationclass:ActivityLifecycleAdapteris just a helper class you’ll need to create which will be an empty implementation ofActivityLifecycleCallbacks(so you don’t have to override each and every methods of that interface when you simply need one of them).